0

按下按钮时抛出异常。该按钮与 segue 相关联(故事板的一部分。

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'changeRooms'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

调用堆栈没有提示异常抛出的位置。在尝试深入研究时,我在 prepareForSegue 中发现了以下内容:(ChooseRoomVC.m while segueing to view controller RoomsListTVC.m)

NSLog (@"navController1: %@", self.navigationController);
NSLog (@"navController2: %@", [[segue destinationViewController] navigationController]);

创建输出:

2013-02-16 15:41:57.201 Wohnungsprotokoll[1906:c07] navController1: (null)
2013-02-16 15:41:57.203 Wohnungsprotokoll[1906:c07] navController2: (null)

在那个阶段,我有点期望destinationViewController 还没有分配navigationController。这就是为什么我将其与其他视图控制器的 prepareForSegue 中的状态进行比较。它们都产生相同的输出:(KeysEditVC.m - 从这里它被连接到 ChooseRoomVC)

NSLog (@"navControllerx: %@", self.navigationController);
NSLog (@"navControllery: %@", [[segue destinationViewController] navigationController]);

输出:

2013-02-16 15:41:52.181 Wohnungsprotokoll[1906:c07] navControllerx: <UINavigationController: 0xa22c5d0>
2013-02-16 15:41:52.182 Wohnungsprotokoll[1906:c07] navControllery: (null)

因此,我检查了 viewDidLoad 中的 self.navigationController (来自chooseRoomVC.m),只是为了查看是否出现了问题,以查看有问题的视图控制器。但这看起来不错:

NSLog (@"navController0: %@", self.navigationController);

输出:

2013-02-16 15:41:52.212 Wohnungsprotokoll[1906:c07] navController0: <UINavigationController: 0xa22c5d0>

因此,显然,当我的视图控制器 (chooseRoomVC.m) 正在执行时,navigationController 分配不知何故在某处丢失了。我确实添加了类似的 NSLogs 到 viewWillAppear 和 viewWillDisappear 并且 self.navigationController 设置正确。

我非常乐意提供代码或屏幕截图等,但我不知道从哪里开始。请指教:

只是为了完整性:我使用故事板和 ARC、iOS 6.1、iOS 模拟器以及 iPhone 设备,在 OS-X 10.8.2 上使用 xcode 4.6。

There is just one thing that may be unusual. The view controller I am segueing to when the error is thrown, can be segued to from a number of view controllers. But I am doing that with more than this one and it works fine in all other cases.

4

1 回答 1

0

Now I found it after it took me ages to nail it down and put everything together for the question.

In IB I copied the button that was associated with this segue from another button of the same view. And from copying from this original there was an assignment of an action left. This IBAction method that was supposed to be associated with another button performed some business logic and called

[self.navigationController popViewControllerAnimated:YES];

So I was segueing further down and returning to the parent view controller at about the same time! Naturally that does not work. However, I'll leave it here so that maybe somebody with the same problem finds the root cause quicker than I did.

于 2013-02-16T15:28:17.160 回答