iOS 7 Popover 控制器在 xcode 6 下崩溃
iOS 7 Popover Controller crashing under xcode 6
每当我尝试在 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。
试试这个:
// write code in .m class
UIPopoverController *PopoverController;
-(void)dealloc
{
if(self.PopoverController)
{
[self.PopoverController dismissMenuAnimated:NO];
}
}
我最终没有调用 segue,而是分配了我试图作为弹出窗口呈现的布局视图控制器,一个情节提要标识符。然后我可以将其用作 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];
}
}
我知道已经晚了,但我希望这个解决方案能帮助其他人。我在我的项目及其工作中使用它。将以下方法添加到您的代码中,使其也适用于 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;
}
每当我尝试在 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。
试试这个:
// write code in .m class
UIPopoverController *PopoverController;
-(void)dealloc
{
if(self.PopoverController)
{
[self.PopoverController dismissMenuAnimated:NO];
}
}
我最终没有调用 segue,而是分配了我试图作为弹出窗口呈现的布局视图控制器,一个情节提要标识符。然后我可以将其用作 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];
}
}
我知道已经晚了,但我希望这个解决方案能帮助其他人。我在我的项目及其工作中使用它。将以下方法添加到您的代码中,使其也适用于 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;
}