IBOutlets到故事板中的其他视图控制器 [英] IBOutlets to other view controllers in storyboard

查看:87
本文介绍了IBOutlets到故事板中的其他视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 UIPageViewController 在多个视图控制器之间切换。这些视图控制器是静态的,所以我想在我的故事板中设计它们。由于不能使用关系或segue将它们连接到 UIPageViewController 而是数据源,我需要一个带有 IBOutletCollection的数据源对象持有页面:

I want to switch between multiple view controllers with a UIPageViewController. These view controllers are static though so i want to design them in my storyboard. Since one can't use relationships or segues to connect them to the UIPageViewController but a datasource, I need to have a datasource object with an IBOutletCollection holding the pages:

@property (retain, nonatomic) IBOutletCollection(UIViewController) NSArray* pages;

虽然,我无法将此插座连接到相关的视图控制器。我想这是因为故事板中的视图控制器完全独立地处理,就像它们在不同的nib文件中一样。有解决方案吗?我不想在代码中设计这些视图控制器。

Although, I am not able to connect this outlet to the view controllers in question. I guess thats because view controllers in a story board are treated completely independently like they were in different nib files. Is there a solution though? I don't want to design these view controllers in code.

推荐答案

IBOutlet可能不是解决这个问题的方法。在我看来,最好的方法是使用你在storyboard中指定的标识符获取nib文件,然后在viewDidLoad方法中输入,并用适用的名称替换变量名和标识符。

An IBOutlet is probably not the way to go about this. The best way to do so in my opinion would be to get the nib file using an identifier that you specify in storyboard and then in the viewDidLoad method, type this in and replace the variable name and identifier with the applicable names.

UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"myIdentifier"];

希望这有助于您使其正常运作。

Hope this helped you get it working.

这篇关于IBOutlets到故事板中的其他视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆