iOS 7 NavigationController Segue Crash

时间:2014-11-13 11:13:23

标签: objective-c iphone ios7 uinavigationcontroller ios8

我有一个NavigationController作为初始视图,一个ViewController作为根视图。从那个根视图我试图做一个segue:

[self.navigationController performSegueWithIdentifier:@"Segue" sender:self];

我的故事板中有另一个视图控制器,我给了segue正确的标识符。在iOS 8上它运行得很完美,但在iOS 7上崩溃时会出现以下消息:

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

我不明白为什么它不适用于iOS 7 ...

更新:这是我的故事板:

enter image description here

3 个答案:

答案 0 :(得分:4)

问题是, segue UINavigationController为来源。

UINavigationController不应执行 segue 。它应该只连接到rootViewController,它可以是UIViewController(或其子类)。应从rootViewController的{​​{1}}执行 segue segue 应将UINavigationController作为其来源,并将其他rootViewController(或其子类)作为其目的地。

您的屏幕截图显示您的UIViewController已与UINavigationController相关联。您现在需要将rootViewController设置为 segue (具有标识符rootViewController)的来源,目前您的Segue作为其来源。现在,从UINavigationController,致电

rootViewController

答案 1 :(得分:1)

这样做:

 [self performSegueWithIdentifier:@"Segue" sender:self];

答案 2 :(得分:0)

如果您已在Self内执行segue,请

使用rootViewController。 如果没有,那就试试吧。

[self.navigationController.viewControllers[0] performSegueWithIdentifier:@"Segue" sender:nil];

希望这会对你有所帮助。

我认为segue storyboardrootViewControllerviewController之间没有Segue {@ 1}},其名称为@“{{1}}”。

相关问题