Answers
先给它在 storyboard 里起一个 ID,比如
MainViewController
。
然后初始化 VC 的时候:
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
MainViewController *mainController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
这是OC,翻译成swift即可。
annie邓
answered 9 years, 9 months ago
参考这篇文章: http://lvwenhan.com/ios/452.html
使用了 StoryBoard 的 viewcontroller 必须从 storyboard 开始初始化,使用这样的代码即可:
let vc = UIStoryboard(name: "Second", bundle: nil).instantiateInitialViewController() as! UIViewController
self.navigationController?.pushViewController(vc, animated: true)
EDG旋转爆炸
answered 9 years, 9 months ago
首先你要在storyboard里面设置这个vc对应的Storyboard ID,如图
然后你在代码里就能直接通过这个id加载这个对象了
XXXViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"xx_id"];
如果
self.storyboard为nil
可以用
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"XX_storyboard_name" bundle:[NSBundle mainBundle]];
XXXViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"xx_id"];
九日的X星
answered 9 years, 9 months ago