UINavigationController 有一个奇怪的问题。
我写了一个应用程序来显示三个级别的数据。(RootView:选择数据 I,第二视图:选择数据 II,第三视图:显示数据)。这很好用,没有问题。
当 PushMessage 到达时出现问题:在这种情况下,我正在尝试使用 UInavigationController 的 setViewControllers: animated: 方法手动创建 viewController Stack:
我正在初始化三个视图控制器(带有数据、标题等)并将它们添加到一个数组中。这个数组被传递给提到的方法(setViewCOntrollers),并且正确显示了顶部 ViewController 的视图。但是当用户触摸左上角的返回按钮时,应用程序崩溃了。这个 Button 的 Title 是栈中前一个 ViewController 的 Title,所以栈看起来是正确的。只有在收到推送通知(即调用 setViewControllers 方法)时显示 rootViewController 的 View 时才会出现此错误。
我的代码:
EMASubstituteTeacherScheduleAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = [appDelegate viewController];
MainViewController *main = [[MainViewController alloc] initWithNibName: @"MainViewController" bundle: nil];
main.navigationItem.title = @"Test";
FormViewController *formSelect = [[FormViewController alloc] initWithNibName: @"FormViewController" bundle: nil];
formSelect.navigationItem.title = @"Test (Level 2)";
formSelect.substDate = [pushData objectForKey: @"date"];
SubstitutesViewController *substDisplay = [[SubstitutesViewController alloc] initWithNibName: @"SubstitutesViewController" bundle: nil];
substDisplay.navigationItem.title = @"Test (Top)";
substDisplay.substDate = [pushData objectForKey: @"date"];
substDisplay.substForm = [pushData objectForKey: @"form"];
NSArray *controllers = [[NSArray alloc] initWithObjects: main, formSelect, substDisplay, nil];
[navController setViewControllers: controllers animated:YES];
控制台上显示的消息:程序接收信号:“EXC_BAD_ACCESS”。
调用堆栈:
'#0 0x3433886c in objc_msgSend'
'#1 0x3061a828 in -[UIApplication sendAction:to:from:forEvent:]
'#2 0x3061a7c8 in -[UIApplication sendAction:toTarget:fromSender:forEvent:]
'#3 0x3061a79a in -[UIControl sendAction:to:forEvent:]
'#4 0x3061a4ec in -[UIControl(Internal) _sendActionsForEvents:withEvent:]
'#5 0x3061ab3a in -[UIControl touchesEnded:withEvent:]
'#6 0x306194ec in -[UIWindow _sendTouchesForEvent:]
'#7 0x30618e66 in -[UIWindow sendEvent:]
'#8 0x30614b5a in -[UIApplication sendEvent:]
'#9 0x30614506 in _UIApplicationHandleEvent
'#10 0x3323a146 in PurpleEventCallback
'#11 0x3293daaa in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
'#12 0x3293f84e in __CFRunLoopDoSource1
'#13 0x3294062c in __CFRunLoopRun
'#14 0x328e98ea in CFRunLoopRunSpecific
'#15 0x328e97f2 in CFRunLoopRunInMode
'#16 0x332396ee in GSEventRunModal
'#17 0x3323979a in GSEventRun
'#18 0x305be2a6 in -[UIApplication _run]
'#19 0x305bce16 in UIApplicationMain
'#20 0x00002512 in main at main.m:14
提前致谢!