I have a UITableViewController that has custom cells that I have customized with my own subclass.
In this subclass, I’ve added a button and I want to push a view into the stack of the navigation controller. I have no idea on how to do that since I don’t know how I can access to the navigation controller from my custom cell.
Any idea?
Need more infos here. What class holds the table, what class is the tableview delegate?
In the most simple case you’re working in one single class. Than it would be
[self.navigationController pushViewController: xyz].But if you have your own subclassed UITableViewCells, than you need to communicate between the cell class and the viewcontroller. You could do this via setting a property in the cell class or your own customCell delegate.
You could also just send a Notification (
[[NSNotificationCenter defaultCenter] postNotification: @"cellButtonTouchedNotification"]) on which your viewController is listening ([[NSNotificationCenter defaultCenter] addListener: self target: @selector(...) name: @"cellButtonTouchedNotification"]). In this case you could use the userInfo property to remember which cell was touched.Anotherway is to make the button accessible from outside (a property eg). Then you could add the target in your tableViewDelegate’s method
cellForRowAtIndexPath:. Smth. like[myCustomCell.button addTarget: self selector: @selector(...)];You could use tags to identify the rowmyCustomCell.button.tag = indexPath.row.