UINavigationControllerに奇妙な問題があります。
データを3つのレベルで表示するアプリを作成しました。(RootView:データIを選択、2番目のビュー:データIIを選択、3番目のビュー:データを表示)。これは問題なく機能します。
PushMessageが到着すると、問題が発生します。この場合、UIInavigationControllerのメソッドsetViewControllers:animated:を使用して、viewControllerスタックを手動で作成しようとしています。
3つのビューコントローラー(データ、タイトルなど)を初期化し、それらを配列に追加しています。この配列は前述のメソッド(setViewCOntrollers)に渡され、上部のViewControllerのビューが正しく表示されます。しかし、ユーザーが左上の[戻る]ボタンをタッチすると、アプリがクラッシュしました。このボタンのタイトルは、スタック内の前のViewControllerのタイトルであるため、スタックは正しいようです。このエラーは、プッシュ通知を受信したときにrootViewControllerのビューが表示された場合にのみ発生します(つまり、setViewControllersメソッドを呼び出します)。
私のコード:
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
前もって感謝します!