【问题标题】:iOS 7 Popover Controller crashing under xcode 6iOS 7 Popover 控制器在 xcode 6 下崩溃
【发布时间】:2015-09-05 06:22:53
【问题描述】:

每当我尝试在 iOS7 上使用 UIPopoverController 时,我的应用程序都会崩溃。据我所知,这是最近出现的问题,仅在内置 Xcode 6 时发生。我没有用于测试的 iOS 7 iPad,但我从 Crashlytics 收到了有人遇到此崩溃的信息。它还在 7.1 模拟器中崩溃。

任何帮助,不胜感激。

干杯

我的代码崩溃了,在prepareForSegue::

if ([[segue identifier] isEqualToString:iPadiOS7ColorPickerSegue])
{
    FCColorPickerViewController *colorPickerVC = [segue destinationViewController];
    colorPickerVC.delegate = self;
    colorPickerVC.isPopover = YES;
    self.popVC = [(UIStoryboardPopoverSegue *)segue popoverController]; // <-- This line
}

错误,请注意 UIStoryboardPushSegue,即使它在情节提要中设置为 Popover。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UIStoryboardPushSegue popoverController]: unrecognized selector sent to instance 0x7a1dd9a0'

编辑

我在一个统一的故事板中设置了视图控制器。此代码可以正常工作,但是在我使用 Xcode 6 进行最新更新后,我开始收到有关此错误的崩溃报告。

我的 segue 选择似乎没有得到尊重,因为它似乎调用了 UIStoryBoardPushSegue。

【问题讨论】:

    标签: ios ipad ios7 storyboard segue


    【解决方案1】:

    试试这个:

    // write code in .m class
    
    UIPopoverController *PopoverController;
    
    -(void)dealloc
    {
    
        if(self.PopoverController)
        {
            [self.PopoverController dismissMenuAnimated:NO];
        }
    
    }
    

    【讨论】:

    • 这与我的问题到底有什么关系? :S
    【解决方案2】:

    我最终没有调用 segue,而是分配了我试图呈现为弹出框的布局视图控制器,即 Storyboard Identifier。然后我可以将它用作 popoverController 的 contentViewController。 (我将无法访问 [segue destinationViewController],因为我不再将其显示为 segue)

    iPhone、iOS7 上的 Push segue 似乎不受影响,所以我保持不变。

    我必须使 (UIPopoverController*) popVC 属性强,以便它保留引用,然后在它被解除时释放它。

    下面是我用来检查 iOS 版本和设备的代码,以及从哪里调用 segues。

    if ([NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)]) {
        // conditionally check for any version >= iOS 8 using 'isOperatingSystemAtLeastVersion'
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            [self performSegueWithIdentifier:kiPadiOS8ColorPickerSegueID sender:nil];
        } else {
            [self performSegueWithIdentifier:kiPhoneiOS8ColorPickerSegueID sender:nil];
        }
    } else {
        // we're on iOS 7 or below
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            //[self performSegueWithIdentifier:kiPadiOS7ColorPickerSegueID sender:nil];
    
            FCColorPickerViewController *colorPickerVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"ColorPickerPopover"];// = [ destinationViewController];
            colorPickerVC.delegate = self;
            colorPickerVC.isPopover = YES;
    
            self.popVC = [[UIPopoverController alloc] initWithContentViewController:colorPickerVC];
            [self.popVC presentPopoverFromRect:CGRectMake(0, CGRectGetHeight(self.view.frame) - 50, CGRectGetWidth(self.view.frame), 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
        } else { // iPhone, iOS 7
            [self performSegueWithIdentifier:kiPhoneiOS7ColorPickerSegueID sender:nil];
        }
    
    }
    

    【讨论】:

      【解决方案3】:

      我知道为时已晚,但我希望此解决方案对其他人有所帮助。我在我的项目及其工作中使用它。将以下方法添加到您的代码中,使其也适用于 iPhone:

      -(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{ 
      if ([identifier isEqualToString:iPadiOS7ColorPickerSegue] && IS_IPHONE) {
      
         FCColorPickerViewController *colorPickerVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FCColorPickerViewController"];
      colorPickerVC.delegate = self;
      colorPickerVC.isPopover = YES;
       [self presentViewController:colorPickerVC animated:YES completion:NULL];
      
          return NO;
      }
      
      return YES;
      

      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-24
        • 2019-08-01
        • 1970-01-01
        • 2016-01-28
        相关资源
        最近更新 更多