sickagain
sickagain

Reputation: 143

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.

Upvotes: 14

Views: 4787

Answers (1)

jrturton
jrturton

Reputation: 119292

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.

Upvotes: 31

Related Questions