我遇到了popToRootViewController和NavigationControllerDelegate组合的奇怪崩溃。 在Storyboard中创建了3个tableViewControllers。 RootViewController - secondViewController - ThirdViewController 然后我想在ThirdViewController上使用popToRootViewController。弹出工作正常,但立即崩溃或在RootView上点击其他东西时。 我在popToRootViewController之后发现NavigationController的childViewControllers是0,但是当逐个弹出后退按钮时,它不会崩溃。
当我禁用NavigationController的委托时,它解决了崩溃,而childViewControllers不会为0。 但我需要NavigationController委托来禁用我用来验证用户输入的textfield的委托。 (即如果用户将强制文本字段留空,则navigationController的委托将在推送/弹出视图之前禁用文本字段委托,以避免由文本字段委托触发alertView,这可以正常工作)。
这是显示childViewControllers count = 0的NSLog输出。我正在计算pop / push视图时childViewControllers的数量。
App启动时(在ViewdDidAppeared中显示NSLog)
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>"
)
将root推送到第二个
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>"
)
第二到第三
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。
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)
但是RootViewController是新创建的吗?但无论如何它都会崩溃。
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>"
)
作为参考,下面是我禁用navigationController的委托时的日志。 如果有任何关于解决这个问题的建议,我们将非常感激。
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>"
)
此致