简体   繁体   English

如何在故事板中设置初始ViewController的委托

[英]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.

相关问题 如何使用故事板设置委托 - How to set the delegate with a storyboard 如何设置初始故事板 - How to set initial storyboard 在情节提要中更改初始ViewController - changing the initial viewcontroller in a storyboard 如何使用给定的根ViewController和初始ViewController实例化情节提要? - How do I instantiate a storyboard with a given root viewcontroller and initial viewcontroller? 没有StoryBoard的情况下如何在两个ViewController之间使用委托? - How to use delegate between two ViewController without StoryBoard? 初始ViewController根据情节提要中的Login进行更改 - Initial ViewController changes as per Login in storyboard 如何使用扩展名设置viewController的搜索栏的委托? - How to set delegate of search bar of viewController using extension? 我如何在没有来自App Delegate的plist的情况下手动选择初始情节提要? - How do I manually select an initial storyboard without the plist from the App Delegate? 如何通过AppDelegate在初始视图控制器(在Storyboard中创建)上设置属性? - How to set properties on initial view controller (created in Storyboard) from AppDelegate? 如何使用PresentViewController在storyboard中引用ViewController - How to reference a ViewController in storyboard with PresentViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM