简体   繁体   English

弹出窗口出现时,应用崩溃

[英]App crashes when popover appears

I am trying to get a popover appear on a press of a button in ios 8, however the app crashes on the press of the button. 我试图在iOS 8中按下按钮时出现弹出窗口,但是按下按钮时应用程序崩溃。 I have set up all storyboards correctly and using breakpoints I determined that it is this line that causes the problem even though the view controller which is meant to be displayed in the popover is of FirstViewController class: 我已经正确设置了所有情节提要板,并使用断点,即使要在弹出窗口中显示的视图控制器是FirstViewController类,也确定是导致此问题的这一行:

UIViewController *vc = destNav.viewControllers.firstObject;

This is the crash: 这是崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController viewControllers]: unrecognized selector sent to instance 0x1446ea3a0' ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[SecondViewController viewControllers]:无法识别的选择器发送到实例0x1446ea3a0'


This is the rest of my code from this part: 这是我本部分剩下的代码:

- (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;
}

I worked it out! 我解决了! Sorry that I am posting this quite late 抱歉,我发布得太晚了

You simply need to exclude the line 您只需要排除该行

 FirstViewController *vc = destNav.viewControllers.firstObject;

even though all tutorials show this line 即使所有教程都显示这一行

尝试像这样转换视图控制器:

FirstViewController *vc = (FirstViewController *)destNav.viewControllers.firstObject;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM