Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segue from UITableViewCell how to include indexPath data?

I have a segue linked from a UITableViewCell to another UITableViewController within a navigation controller, and I need to setup the second UITableViewController based on the cell I'm segueing from.

The didSelectRowAtIndexPath method gives me that information but it gets called AFTER the prepareForSegue so I can't get the information I need in time.

I tried a couple of different things:

I've tried dragging a segue from another area on the first UITableViewController so I can just call the segue in code in the didSelectRowAtIndexPath method, but nothing seems to "stick".

There doesn't seem to be a way to just get the row and section from the UITableViewCell (it's the 'sender' in the prepareForSegue), unless I've missed something.

like image 459
sickagain Avatar asked Feb 24 '12 07:02

sickagain


People also ask

How do you get the IndexPath row when a button in a cell is tapped?

You can walk up the view hierarchy to find the containing table view cell and the containing table view. Then you can ask the table view for the cell's index path. Then use it to find the index path like this: func addButtonTapped(_ sender: Any) { guard let button = sender as?


1 Answers

In prepareForSegue:, the table view's indexPathForSelectedRow will be the path of the tapped row, if your segues are coming straight from the cells.

Or, you can use the table view's indexPathForCell: method.

like image 106
jrturton Avatar answered Sep 17 '22 23:09

jrturton