generaltsow
generaltsow

Reputation: 205

Table View Cell Segues not Working

I'm trying to do something very simple: set up a segue so that when you click on a cell in a table it will take you to another View Controller. The problem, I believe, originates from the fact that the TableView these cells are in is embedded in a regular ViewController (as opposed to a TableViewController), and is one of two subviews in this ViewController.

As far as I can tell, I've set everything up correctly: I embedded the ViewController with the two subviews in a Navigation Contoller, set it to be the dataSource and delegate for the TableView, and created a push segue from a TableViewCell to my second View Controller in the storyboard. However, when the app is run and a user clicks a row in the table, it merely selects the row and the segue doesn't fire at all (I've debugged it and the prepareForSegue function isn't even being called).

Is there something I'm missing here? Or is this for some reason not possible if the TableView is not the only view in its view controller?

Upvotes: 9

Views: 9145

Answers (6)

user1762670
user1762670

Reputation:

I had the similar issue. Fix is 1. Write SegueIdentifier for the segue in Storyboard 2. Add the following line [self performSegueWithIdentifier:@"SegueIdentifier" sender:nil]; in didSelectRowAtIndexPath.

I hope this would help.

Upvotes: 0

Out of Orbit
Out of Orbit

Reputation: 563

Had the same problem. Segue from a prototype table view cell inside a regular View Controller would make the app crash. In case someone have the same problem.

My solution:

If you are using a push segue make sure your first View Controller with the table view is embedded in a Navigation Controller otherwise "push segues" wont work. Also point the segue at the destination View Controller, not its Navigation Controller!

And as mentioned earlier, make sure your "segue identifiers" are correct.

at "didSelectRowAtIndexPath" I call "[self performSegueWithIdentifier:@"Your_destination_View_Controller" sender:self];

Upvotes: -1

wcochran
wcochran

Reputation: 10896

I find that if I had recently wired the segue from the cell's accessory view, and later delete the segue and try to wire a new segue to the cell directly it does not work (using Xcode 4.6.2) -- Xcode keeps connecting the segue to the accessory view (even if there isn't one)! The way I fixed it is by selecting the cell in IB and using the connection inspector to (1) delete the original "accessory action" segue and (2) directly wire the "selection" segue by dragging from the filled circle in the image below to the appropriate destination view controller.

enter image description here

Upvotes: 6

Rodinia
Rodinia

Reputation: 41

If you have customized the cell rendering, e.g.:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

then ensure you are using the same cell identifier as specified for the prototype cell in ste story.

So in this case the 'Identifier' of the cell which hooked up the segue should be set to 'Cell'.

Upvotes: 4

LNI
LNI

Reputation: 121

This may or may not help you, but I ran into this issue because I had defined two different cell types, and had provided didSelectRowAtIndexPath implementation. I had to add [self performSegueWithIdentifier:@"Whatever" sender:self] as part of didSelectRowAtIndexPath and the issue got resolved.

If you are able to at least detect row selections, you may be able to take advantage of this method.

Upvotes: 4

GoZoner
GoZoner

Reputation: 70135

If you are creating the StoryBoard in Xcode then do the following:

  1. Create a UITableViewController
  2. Add a prototype UITableViewCell
  3. Create the UIViewController that will be your segue target.
  4. Control-Click on the prototype UITableViewCell and drag to the segue target.

That's it. You'll probably want to edit the characteristics of the UITableViewCell to be, for example, your subclass of UITableViewCell.

Upvotes: 2

Related Questions