Show ViewController from XIB-file-Button - Swift

五迷三道 提交于 2019-12-03 08:23:30

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