还有其他人在 iOS 8 中遇到 UIImagePickerController
问题吗?下面的方法在 iPad 上的 iOS 7 中运行得非常好,但是当我在 XCode 6(Beta 3 或 4)中运行它时,当我尝试显示选择器(最后一行)时出现以下错误。如果重要的话,sourceType 的选择来自显示在同一位置的 alertView。
Warning: Attempt to present <UIImagePickerController: 0x7c0ae400> on <CAGUCreateContactViewController: 0x7bf61a00> which is already presenting (null)
打开图片选择器的方法。
- (void)openPhotoPicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.sourceType = sourceType;
imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
imagePickerController.delegate = self;
self.imagePickerController = imagePickerController;
if (sourceType == UIImagePickerControllerSourceTypeCamera) {
[self presentViewController:self.imagePickerController animated:YES completion:nil];
} else {
if (self.popoverVC) {
[self.popoverVC dismissPopoverAnimated:YES];
self.popoverVC = nil;
}
self.popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.popoverVC presentPopoverFromRect:self.nameAndPicCell.picture.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
}
}
最佳答案
我认为这是因为在 iOS 8 中,警报 View 和操作表实际上是呈现的 View Controller (UIAlertController
)。因此,如果您要呈现一个新的 View Controller 以响应来自 UIAlertView
的操作,它会在 UIAlertController
被关闭时呈现。我通过将 UIImagePickerController
的呈现延迟到运行循环的下一次迭代来解决这个问题,方法是:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self openPhotoPicker:sourceType];
}];
但是,解决此问题的正确方法是在 iOS 8 上使用新的 UIAlertController
API(即使用 if ([UIAlertController class])
... 来测试为了它)。如果您还不能使用新的 API,这只是一种解决方法。
关于ios - UIImagePickerController 不在 iOS 8 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24942282/