Create Segue from Custom Cell UIButton to a ViewController

882 Views Asked by At

I want to create a segue from (a) a UIButton (in a custom cell of a tableview) and (b) a custom cell in general to a UIViewController. The custom cell is specified in a .xib file. I read that I just should control drag from the UIButton / custom cell to the UIViewController. That doesn't work for me.

  1. The .xib file of the custom cell isn't inside the storyboard - that's right? I thought about that it should be inside the storyboard. If necessary, how can I do that?
  2. How can I create a segue from the UIButton (in a custom cell) / custom cell to the UIViewController?

Thanks!

EDIT: I'm using a UITableViewController as Source, the destination is a UIViewController with a UITableView.

2

There are 2 best solutions below

5
zisoft On BEST ANSWER

Ctrl-drag from the tableViewController (not from the prototype cell) to your target viewController and assign an identifier name to the segue.

Now override didSelectRowAtIndexPathto perform the segue with your identifier when tapping that cell:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)    
{
    performSegueWithIdentifier("yourSegue", sender: nil)
}

Distinguish between the cells based on your indexPath and create as many segues as you need to your target viewControllers.

You can do similar for the button in your custom cell. Perform the segue on the button's action.

0
Joe On

I used xcode6beta5 that should be the problem. Now I'm using xCode6 GM and the creation of the segues works absolutely fine like zisoft wrote! Thanks man!!