0

Hopefully someone can help.

I've got an app that uses the UISplitViewController however I've now had to start using multiple storyboards because i've got a large amount of views and Xcode was starting to run really slow. I've moved moved the UIViewControllers to multiple storyboards.

The Master View is built from static cells, so when the user selects the cell I normally change the view by pushing a segue.

I'm now wondering how to programmatically change the detail view of a UISplitViewController?

Thanks

1 Answer 1

4

Subclass UISplitViewController and set your root splitViewController to that class. Then add this method to your UISplitViewController subclass:

-(void)setDetailControllerTo:(UIViewController *)detailController withNavControllerTitle:(NSString *)title {
    [detailController view]; // this line forces the viewDidLoad method to be called

    if (title) {
        UINavigationController *navController = [[UINavigationController alloc] init];
        [navController pushViewController:detailController animated:YES];
        detailController.title = title;

        NSArray *viewControllers=@[self.mainController.viewControllers[0],navController];
        self.mainController.viewControllers = viewControllers;
    } else {
        NSArray *viewControllers=@[self.mainController.viewControllers[0],detailController];
        self.mainController.viewControllers = viewControllers;
    }
}

To call this method do something like this from the master view controller:

FixedSplitViewController *splitController = (FixedSplitViewController*) self.splitViewController;

CurrentEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"CurrentEventViewController"];
// add any setup code here
[splitController setDetailControllerTo:controller withNavControllerTitle:@"Current Event"];

A lot of my projects require the splitviewcontroller to always show the master view so I use this subclass to keep the master view from hiding on portrait rotation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.