Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
I have such a structure
ViewController
UITableView
UITableViewCell
UICollectionView
UICollectionViewCell
I need to send some data to the ViewController when the UICollectionViewCell tapped. How can I achieve that? I stucked at that point
 
@PhoneyDeveloper I have tried protocol way. But I couldn't realize how to assign a delegate from ViewController inside UICollectionViewCell. Could you explain it a little ?
 
Your tableView cell will have a delegate property, so you need to assign the delegate to the view controller, or where ever the implementation of the delegate methods live. e.g. tableCell.delegate = self
 
You can do it in one step or more than one step. I assume your ViewController builds the UITableViewCell. When it does so it sets a delegate. I'll assume the UITableViewCell creates the UICollectionViewCell (or something the UITableViewCell creates then creates the UICollectionViewCell). When that happens either the same delegate is passed to the UICollectionViewCell or more likely there is more than one delegate protocol. You can have one delegate on the ViewController and one on the TableViewCell. When the CollectionViewCell is tapped it calls the TableViewCell delegate, which then calls the ViewController delegate.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.