I'm currently developing for iOS 8 and developing an app with the new adaptive framework. The weird part is when I use the the splitviewcontroller on iPhone with this storyboard configuration the app does not start with the master view controller but the detail controller. Is this a bug and how could I be able to fix it?
This does only happen if the navigationController that envelops the master exists, if I remove it the app starts with master controller.
The thing to realise is that when a split view controller app starts on iPhone 6 Plus in portrait, it is just showing the split view controller in its collapsed state. By default this has the detailed view pushed above any view controllers in the primary navigation controller.
The way to stop a particular view (such as a blank detail view you may initially show on iPad) from being displayed at launch, or indeed after any rotation to portrait, is to handle this in the splitViewController:collapseSecondaryViewController:ontoPrimaryViewController: delegate method. This will be called at launch on iPhone or iPhone 6 Plus in portrait before presentation.
Doing this, you shouldn't need to have any device specific code.
In its simplest form this would look like:
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
{
if ([secondaryViewController isKindOfClass:[BlankViewController class]])
{
// If our secondary controller is blank, do the collapse ourself by doing nothing.
return YES;
}
// Otherwise, use the default behaviour.
return NO;
}
Obviously, you then need to do the reverse in splitViewController:separateSecondaryViewControllerFromPrimaryViewController: to create and return a BlankViewController for the new secondary view if you don't want your topmost primary view controller to end up on the detail side after split view expands.
Be aware mixing your own implementation with Apple's in these methods, they do some crazy stuff like embedding UINavigationControllers inside other UINavigationControllers. See my related answer here: https://stackoverflow.com/a/26090823/4089333
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With