User
User

Reputation: 24731

Segue not working in Tabbed App with TableView and Navigation Controller

I've just read and watched about 20 videos, StackOverFlow questions and articles but they're all outdated. This tutorial and video were the most helpful. You can see I followed the steps, but nothing happens when I click a cell.

I also overwrite didSelectRowAtIndexPath with some actions, and that executes properly when I click a cell, but the segue doesn't do anything.

I'm trying to setup my app so users look at the 2 tabs (each containing TableView) and can click on a cell to be sent to another screen. Similar to the interface of Twitter... tabs, and click on a TableView cell to view individual information.

When I used the Editor > Embed In feature of Xcode, it placed the Navigation Controller before the Table View. However, previously, I've been trying to: TabView -> UINavigationController -> UIViewController. I'm not sure who is right here. I tried both, and both didn't cause the view to change when I clicked a cell.

This should be able to be done without code, right?

1st attempt: Below I've done the first tab using the Editor > Embed In feature.

enter image description here

Another different approach/attempt: Below I've dragged in a navigation controller (which brought 2 boxes, one being a TableView for some reason) and setup a segue from the original TableView to the navigation controller.

enter image description here

Upvotes: 2

Views: 689

Answers (3)

borchero
borchero

Reputation: 6002

I think either you have to do a manual segue, give an identifier to it and then call that segue by

self.performSegueWithIdentifier("myIdentifier", sender:self)

in your

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

or you do your segue in your storyboard by holding "ctrl" and then drag from your cell to the view Controller you want to go to. When you have NavigationController in front of your second ViewController, you have to drag to the NavigationController.

Actually this should work, I've used both of these quite a lot of times so far and I never had problems with it.

Upvotes: 1

carlodurso
carlodurso

Reputation: 2894

There were two parts missing in your project:

  1. The identifier for the segue on the Main.storyboard. I named it details.
  2. self.performSegueWithIdentifier("details", sender: self) in the tableView delegate didSelectRowAtIndexPath.

Happy xCoding.

Upvotes: 1

iamdavidlam
iamdavidlam

Reputation: 404

I was about to comment, but i do not have enough reputation.

in addition to what @minneostasteve said, your storyboard is actually correctly set up in the first pic but not in the second pic

ie. tab bar controller -> navi controller -> tableviewcontroller -> viewcontroller

Upvotes: 0

Related Questions