Post not yet marked as solved
Post marked as unsolved with 4 replies, 2,423 views
Hi!I have protocol AllNotebookDelegate:protocol AllNotebookDelegate: class {
func passData(text: String,nameOfNotebook: String)
}And also I have class AllNotebookCollectionVC with collectionView(didSelectRowAt:) method:class AllNotebookCollectionViewController: UICollectionViewController {
//MARK: - Variables
var notebookItems: [NotebookItem] = []
weak var delegate: AllNotebookDelegate?
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedItem = notebookItems[indexPath.item]
delegate?.passData(text: selectedItem.text, nameOfNotebook: selectedItem.titleOfNotebook)
// Present EditorVC
let editorVC = storyboard!.instantiateViewController(withIdentifier: "editorVC")
let navigationController = UINavigationController(rootViewController: editorVC)
present(navigationController, animated: true, completion: nil)
}
}This is editorVC:class EditorViewController: UIViewController {
//MARK: - Variables & Outlets
@IBOutlet weak var textView: UITextView!
//MARK: - Private methods
override func viewDidLoad() {
super.viewDidLoad()
let allNotebookVC = storyboard?.instantiateViewController(withIdentifier: "allNotebookVC") as! AllNotebookCollectionViewController
textView.text = ""
allNotebookVC.delegate = self
}
extension EditorViewController: AllNotebookDelegate {
func passData(text: String, nameOfNotebook: String) {
titleOfNavigationBar = nameOfNotebook
textView.text = nameOfNotebook
}When I add a breakpoint at collectionView(cellForRowAt:) in AllNotebookVC debugger show me this:collectionViewUICollectionView0x00007fee26878c00indexPathIndexPath2 indicesselfScroll.AllNotebookCollectionViewController0x00007fee25c09b00UIKit.UICollectionViewControllerUICollectionViewControllernotebookItems[Scroll.NotebookItem]1 valuedelegateAllNotebookDelegate?nilnoneselectedItemScroll.NotebookItem0x0000600003add100titleOfNotebookString""nameOfImageOfNotebookString"wallper"textString""editorVCScroll.EditorViewController0x00007fee25e0f580UIKit.UIViewControllerUIViewControllertextViewUITextView?nilnonetitleOfNavigationBarString""navigationControllerUINavigationController0x00007fee27015200UIKit.UIViewControllerUIViewControllerSo, why delegate = nil?