[英]How to set the delegate of initial ViewController in a storyboard
I have a Storyboard like this: 我有一个这样的故事板:
-- initial --> [PictureListViewController] ----> [PictureDetailViewController]
Now I want to set the delegate of my ViewController PictureListViewController
. 现在我想设置我的ViewController PictureListViewController
的委托。 Since it is the first ViewController I can't do this in the method -(void)prepareForSegue:...
since I the initial ViewController is created by the Storyboard framework. 因为它是第一个ViewController我不能在方法中做到这一点-(void)prepareForSegue:...
因为我初始的ViewController是由Storyboard框架创建的。
For re-usability I also don't want the PictureListViewController
so set it's own delegate
. 为了重用,我也不希望PictureListViewController
设置它自己的delegate
。
What is the best practise for this. 这是什么最好的做法。 I could of course create another "empty" ViewController which then segues to the PictureListViewController
but this does not feel like the right thing to do for me. 我当然可以创建另一个“空”ViewController,然后将其转移到PictureListViewController
但这对我来说感觉不对。
Your help is very welcome. 非常欢迎您的帮助。 Thanks :-) 谢谢 :-)
You could set this in the App Delegate by grabbing a reference to your root view controller using... 你可以通过使用...获取对根视图控制器的引用来在App Delegate中设置它。
YourFirstViewController *ctr = self.window.rootViewController;
// Do stuff here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.