NSInternalInconsistency异常:指定的模式表示样式没有相应的表示控制器



更新到iOS 8.0 SDK后,我现在在尝试从UITableViewCell:中呈现UIImagePickerController时出错

*** Assertion failure in -[PartsSearchViewController 
_presentViewController:withAnimationController:completion:], 
/SourceCache/UIKit/UIKit-3318.0.1/UIViewController.m:5726
*** Terminating app due to uncaught exception 
'NSInternalInconsistencyException', 
reason: 'The specified modal presentation style doesn't 
have a corresponding presentation controller.'

我的UITableViewCell"PartCell"是这样声明的:

@interface PartCell : UITableViewCell <UIImagePickerControllerDelegate>

它在下面的PartCell的presentViewController行失败:

- (IBAction)takeAuditImageClicked:(id)sender {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = (id)self;
    picker.allowsEditing = YES;
    picker.modalPresentationStyle = UIModalPresentationNone;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    // FAILING ON THE LINE BELOW:
    [[UIViewController topMostController] presentViewController:picker animated:YES completion:NULL];  
}

以下是生成单元格的UIViewController"PartSearchViewController"的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"partCell";
    UINib *nib = [UINib nibWithNibName:@"PartCell" bundle:nil];
    [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
    PartCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];// forIndexPath:indexPath];
    if (cell == nil)
    {
        cell = [[PartCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    [self fetchedResultsController:[self fetchedResultsControllerForTableView:tableView] configureCell:cell atIndexPath:indexPath];
    return cell;
}

在查看了UIViewControllerUIImagePickerController文档之后,我不知道它发生了什么变化,导致代码现在失败了。

出现问题

    picker.modalPresentationStyle = UIModalPresentationNone;

注释行或将演示文稿样式选项更改为任何其他值都不会引发错误。

我猜8.0之前的SDK只是忽略了这个设置,并默认为UIModalPresentationFullScreen,但这绝对是猜测。如果有人有更好的答案,我会做相应的标记!

来自苹果文档:

UIModalPresentation

一种非模态的观点陈述或否定。

在iOS 7.0及更高版本中可用。

(在modalPresentationStyle可用的七个演示风格选项中,UIModalPresentationNone是唯一抛出上述错误的选项。)

相关内容

最新更新