IBOutlets to other view controllers in storyboard

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 12:52:19

问题


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;

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.


回答1:


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.



来源:https://stackoverflow.com/questions/8898445/iboutlets-to-other-view-controllers-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!