I have custom Collection View Cell
and .swift and .xib file for it. In the .xib file I have textField
which I have to take the data from in Collection ViewController
and act accordingly but I am not sure how because the .xib file has the custom class of the Collection View Cell
and I cannot create outlet to the Collection ViewController
file so I can refer to it.
And if I create an outlet in Collection View Cell
I can't refer to it in Collection ViewController
.
You can't do that. You can't create an outlet that references a UITextField placed inside a custom CollectionViewCell in your CollectionViewController.
What you can do is create an outlet that references the UITextField in your .xib in the respective CollectionViewCell .swift class (1), create an outlet that references your collectionView in the CollectionViewController (2), and use these CollectionViewCells in your collectionView (3).
You can then access the UITextField of a specific CollectionViewCell in your CollectionViewController through the cell itself (3), like for instance with:
let indexPath = IndexPath(row: 2, section: 0)
let cell = self.collectionView.cellForItemAtIndexPath(indexPath) as! CollectionViewCell // so the compiler knows that the cell you are referring to is of type CollectionViewCell and thus has your custom textField property
let textInTextField = cell.textField.text
(1)
(2)
(3)