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

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

如图

在这一页加载那个storyboard

伊谢尔伦
伊谢尔伦

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

membalas semua(3)
阿神

首先你要在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"];
小葫芦

参考这篇文章: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)
巴扎黑

先给它在 storyboard 里起一个 ID,比如MainViewController

然后初始化 VC 的时候:

UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];  
MainViewController *mainController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];

这是OC,翻译成swift即可。

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!