Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Segue from Static Cell not working

I want to open a view controller when I click on a static cell. I created a segue from the static cell to the view controller but it doesn't not work. I tried both push and modal. It does not even reach the prepare to segue method. What am I missing?

If I put a button in the static cell and connect a segue from the button to the view controller then it works. But I do not want a button, I just want a segue from static cell.

Your help is appreciated and much needed. Thanks, Rajat

4 Answers

Did you connect it to accessory action instead of selection?

see if the didSelectCellAtIndexPath method gets called at all. Also check and see if you gave that static cell a unique identifier. I would think what you did would have worked. You could also try removing that segue completely, and adding it again. Sometimes that will fix things.

John W I checked again it is accessory action. Stone Preston - I did give the static cell a unique identifier. I also implemented the didSelectCellAtIndexPath, but that doesn't get called either.

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Hi there in selection"); if (indexPath.section == 3) { NSLog(@"Hi there"); } }

Any other ideas?

Thanks for your help.

Connect the segue via selection, i.e. not accessory action.

  • Selection triggers segue when anywhere within the row is tapped
  • Accessory action triggers segue when the accessory button, e.g. disclosure button is tapped.

One thing to remember with static tableview is that you need to set up segue for each row instead of just one. Here's what it will look like in the storyboard: https://www.dropbox.com/s/jcgtxx1vjvp1y8q/Screenshot%202013-12-27%2014.15.28.png

On why didSelectRowAtIndexPath is not called, make sure in your storyboard your tableview's delegate outlet is connected to your view controller.

I was just experiencing the same issue and I discovered that I had previously set the Selection property of my Table View to No Selection within the Attributes Inspector in IB.

Hope that helps.