ios - 如何在一个视图控制器类中用Swift调用Storyboard
伊谢尔伦
伊谢尔伦 2017-04-17 15:45:26
0
3
703

有一个标签页继承自UIViewController,这个视图控制器的界面使用storyboard实现的,如何在加载视图控制器的时候打开的是已经设计好的相应storyboard的UI界面?

如图

在这一页加载那个storyboard

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
阿神

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"];
小葫芦

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)
巴扎黑

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!