How to create a UIViewController layout in storyboard and then use it in code?

一笑奈何 提交于 2019-11-28 23:37:00
mafis

Take a look at the UIStoryboard class. There is a instantiateViewControllerWithIdentifier Method. So you need to set the Identfier within the Storyboard Editor for your ResultsController ViewController.

You can do something like this

UIViewController *viewController = 
   [[UIStoryboard storyboardWithName:@"MainStoryboard" 
                              bundle:NULL] instantiateViewControllerWithIdentifier:@"ResultsController"];

[self presentModalViewController:viewController animated:NO];

In your storyboard:

  1. Add a generic UIViewController.
  2. With the Identity Inspector, set its custom class as your ResultsController.
  3. Create a modal segue from your source view controller to the ResultsController

For Swift 4

let viewController = UIStoryboard.init(name: "MainStoryboard", bundle: nil).instantiateViewController(withIdentifier: "ResultsController")
self.present(viewController, animated: true, completion: nil)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!