Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard TableView with Segues to Multiple Views

I am having an issue with designing a storyboard. I currently have an app in the app store that was designed with XIB files. I have a tableView placed on a UIViewController - not a tableViewController - that loads a unique viewController for each row that is selected.

I am trying to convert this concept to a storyboard. I've done the following

  1. Place a UIViewController in the Storyboard.

  2. Place a UITableView on the UIViewController so I can customize the table view.

  3. I tried making connections to multiple ViewControllers from the UITableViewCell and I am not allowed.

  4. I tried creating multiple segues from the UIViewController - which I can - but when I click on the cells the segues are not fired. I tried using didSelectRowAtIndexPath: and prepareForSegue:

Since this did not work I tried creating a project with a UITableViewController and then created multiple segues from the UITableViewController. I then named each segue and used the didSelectRowAtIndexPath: method to test the selected cell and called performSegueWithIdentifier: and this did not work. As I clicked on cells I would get random loading of the incorrect viewController. I've copied a bit of my code and few screen shots below.

I am wondering if I am blatantly missing something obvious or do I have to revert to a xib format for this type of project?

override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
{
    if indexPath.row == 0
    {
        println("Segue1")
        self.performSegueWithIdentifier("Segue1", sender: self)
    }
    else if indexPath.row == 1
    {
        println("Segue2")
        self.performSegueWithIdentifier("Segue2", sender: self)
    }
    else if indexPath.row == 2
    {
        println("Segue3")
        self.performSegueWithIdentifier("Segue3", sender: self)
    }

}

Storyboard with named Segues

Take care,

Jon

like image 390
jonthornham Avatar asked Jan 24 '15 03:01

jonthornham


1 Answers

The method override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) is called when an item is deselected.

To call a method when an item is selected, change the method name to override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

like image 173
sameer-s Avatar answered Jan 03 '23 15:01

sameer-s