简体   繁体   中英

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 . 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.

For re-usability I also don't want the PictureListViewController so set it's own 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.

Your help is very welcome. Thanks :-)

You could set this in the App Delegate by grabbing a reference to your root view controller using...

YourFirstViewController *ctr = self.window.rootViewController;
// Do stuff here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM