Show ViewController from XIB-file-Button - Swift

柔情痞子 提交于 2019-12-04 13:42:13

问题


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!


回答1:


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)



回答2:


  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)
}


来源:https://stackoverflow.com/questions/29238560/show-viewcontroller-from-xib-file-button-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!