Reputation: 1586
I have a segue set up between a UITableViewCell
and a UIViewController
. My understanding is that if I set up a Show segue from the prototype cell to a UIViewController
, the UIViewController
will be shown when tapping on one of the cells in my UITableView
, but that's not happening for me. The only way to get it to work is to override the tableView didSelectRowAtIndexPath
, and then call performSegueWithIdentifier
.
To test this out, I threw together a quick project with a UITableViewController
and a UIViewController
. When I created a segue between the prototype cell and the UIViewController
, it worked the way it should. So I know that it is possible, I'm just not sure what could be causing the problems in my actual project.
There's not much code to show for this. My prototype cell is a custom cell that comes from an xib file, but I also tried giving it a class of UITableViewCell
, and it made no difference.
Has anyone ever run in to a case where a segue like this should work, but doesn't? If so, how did you fix it?
Upvotes: 0
Views: 733
Reputation: 2413
Let's clearify some essential things
performSegueWithIdentifier: sender:
is a method of UIViewController, so in order to perform segue from cell you need to declare weak property of your VC in cell, like this@property (nonatomic, weak) UIViewController *segueController;
end perform you action via
[self.segueController performSegueWithIdentifier:@"segue_id" sender:self];
didSelectRowAtIndexPath
has the following benefits: your segue logic belongs to controller, not to the view (because uitableviewcell is a child of uiview). so, i recommend you use this method for segues or manipulating with view hierarchyUpvotes: 2