gpt4 book ai didi

ios appDelegate 窗口 setRootViewController 崩溃

转载 作者:行者123 更新时间:2023-11-29 10:43:08 25 4
gpt4 key购买 nike

我正在开发一个通用的应用程序。在 iphone 版本中,我使用标准的 UINavigationController 堆栈进行导航,一切都很好。然而,在 ipad 版本中,我对所有内容都使用 UISplitViewContoller nav,但登录屏幕只是标准的 UIViewControllers。直到最近我不得不在细节方面稍微改变一下导航时,这一切都很好。基本上现在取决于主控中加载的内容,我必须在细节导航 Controller 中删除堆栈并替换它的根。从那时起,有时当您点击注销并且每次 session 超时并且用户被发送到登录屏幕时,应用程序崩溃:

* 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];
});

任何帮助都会很棒!

最佳答案

这可能与分割 Controller 上尚未完成的动画或过渡有关。也许是警报 View ?

无论如何,我建议在未更改的 rootController 的“顶部”以模态方式呈现登录 Controller ,这样您就不必处理 Controller ,并且可以在登录 Controller 中输入/输出动画。


例如:presentViewController:animated:completion:

关于ios appDelegate 窗口 setRootViewController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23483321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com