有一个标签页继承自UIViewController,这个视图控制器的界面使用storyboard实现的,如何在加载视图控制器的时候打开的是已经设计好的相应storyboard的UI界面?
如图
在这一页加载那个storyboard
阿神2017-04-17 15:47:26
First you need to set the Storyboard ID corresponding to this vc in the storyboard, as shown in the picture
Then you can load the object directly through this id in the code
XXXViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"xx_id"];
It can be used if
self.storyboard is nil
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"XX_storyboard_name" bundle:[NSBundle mainBundle]];
XXXViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"xx_id"];
高洛峰2017-04-17 15:47:26
Refer to this article: http://lvwenhan.com/ios/452.html
The viewcontroller using StoryBoard must be initialized from the storyboard, just use this code:
let vc = UIStoryboard(name: "Second", bundle: nil).instantiateInitialViewController() as! UIViewController
self.navigationController?.pushViewController(vc, animated: true)
巴扎黑2017-04-17 15:47:26
First give it an ID in the storyboard, such as MainViewController
.
Then when initializing VC:
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
MainViewController *mainController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
This is OC, just translate it into swift.