更新到iOS 8.0 SDK后,我在尝试从UIImagePickerController
内展示UITableViewCell
时收到错误:
*** 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
&#34; PartSearchViewController&#34;的代码。生成细胞:
- (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;
}
在查看了UIViewController
和UIImagePickerController
文档后,我无法弄清楚代码现在发生了哪些变化。
答案 0 :(得分:5)
问题在于
picker.modalPresentationStyle = UIModalPresentationNone;
注释该行或将表示样式选项更改为任何其他值都不会引发错误。
我猜测8.0之前的SDK只是忽略了这个设置并默认为UIModalPresentationFullScreen - 但这绝对是一个猜测。如果有人有更好的答案,我会相应地做出标记!
来自Apple文档:
UIModalPresentationNone
非模态视图演示或解雇。
适用于iOS 7.0及更高版本。
(在modalPresentationStyle
可用的七种演示风格选项中,UIModalPresentationNone
是唯一一个抛出上述错误的人。)