我试图在按下ios 8中的按钮时出现弹出窗口,但是按下按钮时应用程序崩溃了。我已正确设置所有故事板并使用断点我确定这条线导致问题,即使要在popover中显示的视图控制器是FirstViewController类:
UIViewController *vc = destNav.viewControllers.firstObject;
这是崩溃:
***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [SecondViewController viewControllers]:无法识别的选择器发送到实例0x1446ea3a0'
这是我这部分代码的其余部分:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Assuming you've hooked this all up in a Storyboard with a popover presentation style
if ([segue.identifier isEqualToString:@"popover"]) {
UINavigationController *destNav = segue.destinationViewController;
FirstViewController *vc = destNav.viewControllers.firstObject;
// This is the important part
UIPopoverPresentationController *popPC = destNav.popoverPresentationController;
popPC.delegate = self;
}
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
答案 0 :(得分:0)
我解决了!对不起,我发布这个很晚了
您只需要排除
行 FirstViewController *vc = destNav.viewControllers.firstObject;
即使所有教程都显示此行
答案 1 :(得分:-1)
尝试像这样投射视图控制器:
FirstViewController *vc = (FirstViewController *)destNav.viewControllers.firstObject;