4

is there a way how to segue from a xib-file (custom TableViewCell) to another ViewController in the Main.storyboard.

There's no possibility to drag a segue, like within the main storyboard.

In the cell I've got a button, from where I want to change the view. How can I solve it?

Thanks!

chrisby
  • 834
  • 7
  • 15
  • Not really an answer, but is there a reason why you use a separate xib instead of the interface builder for layouting the cell? – Thomas Mar 24 '15 at 17:13

2 Answers2

8

You can always instantiate a view controller from your Storyboard and present it on button tapped:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewControllerID") as UIViewController
    self.presentViewController(vc, animated: true, completion: nil)
juliensaad
  • 2,019
  • 2
  • 20
  • 27
  • When I use this code, it says 'TableViewCell.swift dies not have a member named presentViewController'. TableViewCell.swift is my swift file to the XIB-file. – chrisby Mar 25 '15 at 12:01
  • TableViewCell.swift is of the type UITableViewCell and is implemented in a tableViewController in the main storyboard – chrisby Mar 25 '15 at 12:09
  • You need to be in your ViewController to activate the transition, so the action of pressing the TableViewCell must be implemented in the ViewController and not directly in your view. – juliensaad Mar 26 '15 at 01:58
0
  1. Define a segue in StoryBoard and specify the identifier, like detail

  2. Perform segue in talbeView(_, didSelectRowAtIndexPath):

Use self.performSegueWithIdentifier to fire a segue

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("detail", sender: nil)
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Cody
  • 4,353
  • 4
  • 39
  • 42