It is possible to use an existing ViewController with PerformSegueWithIdentifier?

后端 未结 7 1526
一整个雨季
一整个雨季 2020-12-31 05:32

I use the method performSegueWithIdentifier:sender: to open a new ViewController from a storyboard-file programmatically. This works like a charm.<

7条回答
  •  醉酒成梦
    2020-12-31 05:41

    I faced this problem today and what I have done is to create the view controller manually and store it's reference. Then every time I need the controller, check first if exists. Something like this:

    MyController *controller = [storedControllers valueForKey:@"controllerName"];
    
    if (!controller)
    {
        controller = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:NULL] instantiateViewControllerWithIdentifier:@"MyControllerIdentifierOnTheStoryboard"];
    
        [storedControllers setValue:controller forKey:@"controllerName"];
    }
    
    [self.navigationController pushViewController:controller animated:YES];
    

    Hope it helps.

提交回复
热议问题