views:

91

answers:

1

Hello everyone,

I have a strange problem with the UINavigationController.

I wrote an App to display data in three levels. (RootView: Select Data I, Second View: Select Data II, Third View: Display Data). This works great, no problems.

The problem appears when a PushMessage arrives: In this case I'm trying to create a viewController Stack manually, using the method setViewControllers: animated: of the UInavigationController:

I'm initializing the three view Controllers (with Data, title, etc) and adding them to an array. This array is passed to the mentioned method (setViewCOntrollers), and the view of the top ViewController is displayed correctly. But when a user touches the Back Button at the top left, the app crashed. The Title of this Button is the Title of the previous ViewController in the stack, so the stack seems to be correct. This error happens only if the rootViewController's View is displayed when receiving the Push Notification (which means calling the setViewControllers method).

My Code:

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];

Message shown at the console: Program received signal: “EXC_BAD_ACCESS”.

Call Stack:

'#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

Thanks in advance!

A: 

I assume you do your User Interface updates in the main thread.

One time I had a crash on navigation when I tried to put a view controller from one navigation stack to another navigation stack. It seems that the view controller, that I am trying to set to another a navigation stack, cannot currently have a parent.

Is your MainViewController the rootViewController of navigationController when the push notification comes in? If that is the case, the framework might not like it when you try to put the MainViewController to the navigation stack manually. You might need to remove the mainViewController from the navigation stack first before you put into the array to set viewControllers. One workaround would be to have a dummy viewController as rootViewController so that you can easily remove your actual root ViewController from the stack using popToRootViewController before you use that viewController on a new navigation stack.

It is a thought that comes to me from your question. Your case might or might not be the same as what I encountered.

tmin