I'm trying to develop a master-detail iOS application (iPad only) from the xCode 6 template. It runs fine with iOS 8 but running it on iOS 7.0 or 7.1 produces a crash at run-time where I've commented:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
// this line throws a "[MasterViewController topViewController]: unrecognized selector sent to instance 0x796dde90"
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
return YES;
}
To reproduce the bug :
I investigated and it seems that object types differs on iOS 7 and iOS 8:
Why this behavior?
Put this under prepareForSegue:
to ensure backwards compatibility.
DetailViewController *controller;
if ([[segue destinationViewController] isKindOfClass:[UINavigationController class]]) {
controller = (DetailViewController *)[[segue destinationViewController] topViewController];
}
else {
controller = (DetailViewController *)[segue destinationViewController];
}
[controller setDetailItem:object];
try this replacement:
if ([splitViewController respondsToSelector:@selector(displayModeButtonItem)]){
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
}
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