我已经挣扎了两天,相信这是我应该寻求帮助的时刻。在搜索了一段时间后,没有任何答案能够解决我的问题。以下是我的应用程序...
在应用程序中,
- 设备为iPad,iOS 6 - RootViewController是NavigationController - TopViewController是TabBarController - 在这个TabBarController中,我从导航栏的右边按钮呈现一个popoverController - 在呈现popover时,有一个按钮允许用户通过拍摄新照片或从现有照片中选择来选择图像。 - 要选择新照片,我使用presentModalViewController:animated:(如果iOS <6)和presentViewController:animated:completion:(如果iOS> 6)呈现UIImagePickerController,以允许用户使用设备相机拍照。 - 我还在呈现之前隐藏状态栏。 - 要从现有照片中选择,我使用presentPopoverFromBarButtonItem:permitArrowDirections:animated:。 - PopoverViewController也由一个TabBarController引用。
以下是问题
- 如果用户先尝试选择新照片,则呈现UIImagePickerController将始终失败,并出现异常“Application tried to present modally an active controller <[name of view controller that try to present]>”。 - 但是,如果用户首先从相机胶卷中选择图像,然后再次尝试拍摄新的图像,它就不会失败。
以下是我尝试过的内容
- 从RootViewController呈现 - 从TopViewController(TabBarController)呈现 - 从popoverViewController本身呈现 - 从TabBarController的一个选项卡呈现 - 在呈现之前隐藏popoverViewController - 从popoverViewController中的textField中resignFirstResponder 以下是我当前正在使用的代码
在应用程序中,
- 设备为iPad,iOS 6 - RootViewController是NavigationController - TopViewController是TabBarController - 在这个TabBarController中,我从导航栏的右边按钮呈现一个popoverController - 在呈现popover时,有一个按钮允许用户通过拍摄新照片或从现有照片中选择来选择图像。 - 要选择新照片,我使用presentModalViewController:animated:(如果iOS <6)和presentViewController:animated:completion:(如果iOS> 6)呈现UIImagePickerController,以允许用户使用设备相机拍照。 - 我还在呈现之前隐藏状态栏。 - 要从现有照片中选择,我使用presentPopoverFromBarButtonItem:permitArrowDirections:animated:。 - PopoverViewController也由一个TabBarController引用。
以下是问题
- 如果用户先尝试选择新照片,则呈现UIImagePickerController将始终失败,并出现异常“Application tried to present modally an active controller <[name of view controller that try to present]>”。 - 但是,如果用户首先从相机胶卷中选择图像,然后再次尝试拍摄新的图像,它就不会失败。
以下是我尝试过的内容
- 从RootViewController呈现 - 从TopViewController(TabBarController)呈现 - 从popoverViewController本身呈现 - 从TabBarController的一个选项卡呈现 - 在呈现之前隐藏popoverViewController - 从popoverViewController中的textField中resignFirstResponder 以下是我当前正在使用的代码
// PopoverViewController, presented by a tab in TabBarController
- (IBAction)takePhoto:(id)sender {
[self.delegate takePhotoWithDeviceCamera];
}
// A Tab in TabBarController, delegate of popoverViewController
- (void)takePhotoWithCamera {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
if ([UIDevice OSVersion] < 6.0) {
[self presentModalViewController:cameraPicker animated:YES];
} else {
[self presentViewController:cameraPicker animated:YES completion:nil];
}
}
你知道是什么导致了这个错误吗?欢迎提出任何建议。谢谢。