【发布时间】:2011-03-17 23:33:58
【问题描述】:
这是我的目标: 我想从 TabBarController 显示 UIImagePickerController,一旦拍摄照片,我希望“使用”按钮带我另一个视图控制器。
我的问题: 我有 MainCameraTabController,它继承自 UIViewController 并用作协调 UIImagePickerController 和选择器委托的启动的类。选择器完成后,我尝试从 MainCameraTabController 启动另一个不同的 ViewController 但我收到错误,
*** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:
如果我在 UIImagePickerController 被解除和我启动下一个控制器之间设置一个定时延迟,它可以正常工作,但我想更优雅地做到这一点。
有没有更好的方法来构建我的类继承,以便我可以让 MainCameraTabController 显示 Picker,然后显示第二个视图控制器?
// #
// # 1. Create the tab bar and add the MainCameraTabController:
// #
// tab1Controller and tab3Controller are also created
cameraTabController = [[MainCameraTabController alloc] init];
tabBarController = [[UITabBarController alloc] init];
NSArray *tabViewControllers = [NSArray arrayWithObjects:tab1Controller,
cameraTabController
tab3Controller, nil];
tabBarController.viewControllers = tabViewControllers;
self.window.rootViewController = self.tabBarController;
// #
// # 2. MainCameraTabController interface & implementation
// #
@interface MainCameraTabController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
}
- (void)showCamera;
@end
@implementation MainCameraTabController
// #
// # 3. Show the camera when the view loads
// #
- (void)viewDidLoad
{
[self startCameraController:self usingDelegate:self];
}
- (void)showNextController
{
FollowupController *fc = [[FollowupController alloc] initWithNibName:@"SomeView" bundle:nil];
// THIS IS THE PROBLEM
[self presentModalViewController:cameraPicker animated: YES];
}
- (BOOL)startCameraController:(UIViewController *)controller
usingDelegate:(id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>)pickerDelegate
{
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
// configure the cameraPicker
// #
// # Apple's doc specifies that UIImagePickerController must be launched with
// # presentModalViewController
// #
[controller presentModalViewController:cameraPicker animated: YES];
}
// UIImagePickerControllerDelegate method called when photo taking is finished
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// work to handle the photo
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
[picker release];
[self showNextController];
}
@end
在相关的注释中,我检查了选择器的 parentViewController 是什么时候
imagePickerController:didFinishPickingMediaWithInfo
被调用,并且父级不是 MainCameraTabController 而是 UITabBarController。不知道为什么会这样。
【问题讨论】:
标签: iphone uiimagepickercontroller