I'm encountering the strange crash with combination of popToRootViewController and NavigationControllerDelegate. There are 3 tableViewControllers created in Storyboard. RootViewController - secondViewController - ThirdViewController Then I want to popToRootViewController on ThirdViewController. Popping works OK but crash immediately or when tap something else on the RootView. I found NavigationController's childViewControllers were 0 right after popToRootViewController but when popping with back buttons one by one, it won't crash.
When I disabled the NavigationController's delegate, it solves the crash and childViewControllers won't be 0. But I need NavigationController delegate to disable textfield's delegate which I'm using to validate user inputs. (i.e. if user left mandatory textfield empty, navigationController's delegate will disable the textfield delegate before push/pop the view to avoid alertView from being triggered by textfield delegate and this works OK).
Here is the NSLog outputs to show the childViewControllers count = 0. I'm counting number of the childViewControllers when pop/push views.
When App started (NSLog in viewdDidAppeared)
2013-06-11 13:05:29.287 MyApp[1389:c07] Childviewcontrollers in Root's viewDidAppear = 1
2013-06-11 13:05:29.289 MyApp[1389:c07] Childviewcontrollers in Root's viewDidAppear = (
"<RootViewController: 0x83239d0>"
)
Push root to second
2013-06-11 13:05:41.955 MyApp[1389:c07] delegate enabled
2013-06-11 13:05:41.956 MyApp[1389:c07] childviewcontrollers count in SecondViewController's NavControlDelegate 2
2013-06-11 13:05:41.956 MyApp[1389:c07] childviewcontrollers in SecondViewController's NavControlDelegate (
"<RootViewController: 0x83239d0>",
"<SecondViewController: 0xfb0ee60>"
)
2013-06-11 13:05:42.322 MyApp[1389:c07] childviewcontrollers count in Second's ViewDidAppear 2
2013-06-11 13:05:42.322 MyApp[1389:c07] childviewcontrollers in Second's ViewDidAppear (
"<RootViewController: 0x83239d0>",
"<SecondViewController: 0xfb0ee60>"
)
Second to Third
2013-06-11 13:05:51.945 MyApp[1389:c07] childviewcontrollers count in SecondViewController's NavControlDelegate 3
2013-06-11 13:05:51.945 MyApp[1389:c07] childviewcontrollers in SecondViewController's NavControlDelegate (
"<RootViewController: 0x83239d0>",
"<SecondViewController: 0xfb0ee60>",
"<ThirdViewController: 0x832f050>"
)
2013-06-11 13:05:52.302 MyApp[1389:c07] childviewcontrollers count in Third's ViewDidAppear 3
2013-06-11 13:05:52.303 MyApp[1389:c07] childviewcontrollers in Third's ViewDidAppear (
"<RootViewController: 0x83239d0>",
"<SecondViewController: 0xfb0ee60>",
"<ThirdViewController: 0x832f050>"
popToRootViewController on Third.
2013-06-11 13:06:02.284 MyApp[1389:c07] Delegate disabled
2013-06-11 13:06:02.284 MyApp[1389:c07] childviewcontrollers in SecondViewController's NavControlDelegate 0
2013-06-11 13:06:02.284 MyApp[1389:c07] childviewcontrollers in SecondViewController's NavControlDelegate (null)
But RootViewController Created newly? But it'll crash anyway.
2013-06-11 13:06:02.642 MyApp[1389:c07] Childviewcontrollers in Root's viewDidAppear = 1
2013-06-11 13:06:02.642 MyApp[1389:c07] Childviewcontrollers in Root's viewDidAppear = (
"<RootViewController: 0x83239d0>"
)
For reference, below is the log when I disabled the navigationController's delegate. If any advice on solving this problem, it would be very much appreciated.
2013-06-11 13:07:06.349 MyApp[1412:c07] Childviewcontrollers count in Root's viewDidAppear = 1
2013-06-11 13:07:06.350 MyApp[1412:c07] Childviewcontrollers in Root's viewDidAppear = (
"<RootViewController: 0x8184680>"
)
2013-06-11 13:07:08.265 MyApp[1412:c07] delegate enabled
2013-06-11 13:07:08.632 MyApp[1412:c07] childviewcontrollers count in Second's ViewDidAppear 2
2013-06-11 13:07:08.632 MyApp[1412:c07] childviewcontrollers in Second's ViewDidAppear (
"<RootViewController: 0x8184680>",
"<SecondViewController: 0xa969ca0>"
)
2013-06-11 13:07:15.442 MyApp[1412:c07] childviewcontrollers count in Third's ViewDidAppear 3
2013-06-11 13:07:15.443 MyApp[1412:c07] childviewcontrollers in Third's ViewDidAppear (
"<RootViewController: 0x8184680>",
"<SecondViewController: 0xa969ca0>",
"<ThirdViewController: 0x74a6a30>"
)
2013-06-11 13:07:18.994 MyApp[1412:c07] Childviewcontrollers count in Root's viewDidAppear = 1
2013-06-11 13:07:18.994 MyApp[1412:c07] Childviewcontrollers in Root's viewDidAppear = (
"<RootViewController: 0x8184680>"
)
Regards,