【发布时间】:2014-06-22 09:29:05
【问题描述】:
我正在开发一个通用的应用程序。在 iphone 版本中,我使用标准 UINavigationController 堆栈进行导航,一切都很好。但是,在 ipad 版本中,我对所有内容都使用 UISplitViewContoller 导航,但登录屏幕只是标准的 UIViewControllers。直到最近我不得不在细节方面稍微改变导航时,这一切都很好。基本上现在取决于主控中加载的内容,我必须在详细导航控制器中擦除堆栈并替换它的根。从那时起,有时当您点击注销并且每次会话超时并且用户被发送到登录屏幕时,应用程序崩溃:
* thread #1: tid = 0x140896, 0x0000000102143fcb libobjc.A.dylib`objc_msgSend + 11, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x0000000102143fcb libobjc.A.dylib`objc_msgSend + 11
frame #1: 0x000000010109ffb2 UIKit`-[UISplitViewController _calculateDelegateHiddenMasterOrientations] + 48
frame #2: 0x00000001010a284b UIKit`-[UISplitViewController hidesMasterViewInLandscape] + 42
frame #3: 0x000000010109fec7 UIKit`-[UISplitViewController _isMasterViewShownByDefault] + 75
frame #4: 0x000000010109fee7 UIKit`-[UISplitViewController _isMasterViewShown] + 23
frame #5: 0x00000001010a2e18 UIKit`-[UISplitViewController viewWillDisappear:] + 70
frame #6: 0x0000000100dd6e42 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 563
frame #7: 0x0000000100dd7ef8 UIKit`-[UIViewController viewWillMoveToWindow:] + 316
frame #8: 0x0000000100d30e00 UIKit`-[UIView(Hierarchy) _willMoveToWindow:] + 430
frame #9: 0x0000000100d2fd2a UIKit`__UIViewWillBeRemovedFromSuperview + 346
frame #10: 0x0000000100d2fb07 UIKit`-[UIView(Hierarchy) removeFromSuperview] + 67
frame #11: 0x0000000100d13f95 UIKit`-[UIWindow setRootViewController:] + 262
* frame #12: 0x0000000100047471 Callidus Enablement`__35+[CEInterfaceFunctions OpenLoginVC]_block_invoke(.block_descriptor=<unavailable>) + 609 at CEInterfaceFunctions.m:186
frame #13: 0x000000010336f851 libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #14: 0x000000010338272d libdispatch.dylib`_dispatch_client_callout + 8
frame #15: 0x00000001033723fc libdispatch.dylib`_dispatch_main_queue_callback_4CF + 354
frame #16: 0x00000001024b6289 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
frame #17: 0x0000000102403854 CoreFoundation`__CFRunLoopRun + 1764
frame #18: 0x0000000102402d83 CoreFoundation`CFRunLoopRunSpecific + 467
frame #19: 0x00000001030fcf04 GraphicsServices`GSEventRunModal + 161
frame #20: 0x0000000100cdde33 UIKit`UIApplicationMain + 1010
frame #21: 0x000000010005f523 Callidus Enablement`main(argc=1, argv=0x00007fff5fbfec50) + 115 at main.m:16
我如何切换详细信息堆栈的示例:
if (![appDelegate.window.rootViewController isKindOfClass:[UISplitViewController class]]) {
appDelegate.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:@"split"];
}
UISplitViewController *splitViewController = (UISplitViewController *)appDelegate.window.rootViewController;
NSArray* VCs = splitViewController.viewControllers;
UINavigationController* masterNav = (UINavigationController*)VCs[0];
UINavigationController* detailNav = (UINavigationController*)VCs[1];
[masterNav popToRootViewControllerAnimated:NO];
[detailNav setViewControllers:@[[masterNav.storyboard instantiateViewControllerWithIdentifier:@"recent"]] animated:NO];
登录界面加载代码示例:
dispatch_async(dispatch_get_main_queue(), ^{
AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
UIStoryboard* sb;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
sb = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
} else {
sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] ;
}
NSLog(@"sb:%@ appd:%@ win:%@ root:%@",sb,appDelegate,appDelegate.window,appDelegate.window.rootViewController);
UIViewController* vc =[sb instantiateViewControllerWithIdentifier:@"login"];
NSLog(@"vc:%@",vc);
appDelegate.window.rootViewController = vc;//Crash happens HERE
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
[appDelegate.window makeKeyAndVisible];
});
任何帮助都会很棒!
【问题讨论】:
-
在调用
appDelegate.window.rootViewController = vc;之前,您是否尝试将委托设置为零splitViewController.delegate = nil? -
@Visput 你拯救了我的一天!只需设置 nil 就不会崩溃。
标签: ios objective-c ipad uinavigationcontroller uisplitviewcontroller