Kri*_*ite 1 objective-c uitableview uiimagepickercontroller ios
更新到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.'
Run Code Online (Sandbox Code Playgroud)
我的UITableViewCell“ PartCell”被这样声明:
@interface PartCell : UITableViewCell <UIImagePickerControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
在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];
}
Run Code Online (Sandbox Code Playgroud)
以下是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;
}
Run Code Online (Sandbox Code Playgroud)
经过寻找后UIViewController和UIImagePickerController文档,我想不出有什么变化吧的代码到现在失败。
问题出在
picker.modalPresentationStyle = UIModalPresentationNone;
Run Code Online (Sandbox Code Playgroud)
注释行或将演示文稿样式选项更改为任何其他值都不会引发错误。
我猜想8.0之前的SDK只是忽略了此设置,而是默认使用UIModalPresentationFullScreen-但这绝对是个猜测。如果有人有更好的答案,我会相应地打上它!
从苹果文档:
UIModalPresentationNone
非模态视图表示或解雇。
在iOS 7.0和更高版本中可用。
(在可用于的七个演示样式选项中modalPresentationStyle,UIModalPresentationNone是唯一引发上述错误的选项。)