Search code examples
uiviewcontrollerswiftuibuttoncustom-cellxcode6-beta5

Show new ViewController after tapping UIButton in a custom cell


Heyhey!

I'd like to show a ViewController with an Action (tappedInside of a UIButton in a custom cell). In this case I can't just control-drag from the UIButton in the custom cell to the NavigationController (ViewController is embedded).

How can I realize that a "tappedInside" on a Button (in a custom cell) in a row of a tableview will show up a new ViewController?

Thank you!


Solution

  • You can trigger when you click a cell with the delegate:

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
      // some code
    }
    

    To open a new viewcontroller, if you use a storyboard you can try this:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let newVC = storyboard.instantiateViewControllerWithIdentifier("myIdentifier") as youClassController
    self.presentViewController(newVC, animated: false, completion: nil)
    

    Hope that help