简体   繁体   中英

How to prevent Storyboard Segue from resetting UIViewController inside UIPopoverController

Here's my problem. With Storyboard's segue I am having a popover segue for a bar button. The UIViewController inside the UIPopoverController requires to load the data from a server. With Storyboards, everytime I close the popover the view is released so whenever the popover appears again it tries to load data again from server. I dont want this behavior. How can I prevent Storyboard from resetting the view controller inside popover controller? Something like what UITabBarController does. UITabBarController calls viewDidLoad for the first time and for the subsequent tab switches viewWillAppear is called.

Segue is designed so. Every time you do segue - view will be loaded. If you need to store it's data - you should store it outside popover and use this method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    if ([[segue identifier] isEqualToString:@"your segue identifier"])
    {
        //get popover
        ViewController *vc = [segue destinationViewController];

        //Set popover data to vc here
    }

which calls before segue, and in this method set data to popover. If you will use it - don't forget to set Segue identifier in Interface Builder.

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