這是我的目標: 我想從TabBarController中顯示UIImagePickerController,一旦拍攝照片,我希望「使用」按鈕帶我另一個視圖控制器。從UITabBarController駕駛UIImagePickerController
我的問題: 我有MainCameraTabController從UIViewController繼承,並作爲編排的啓動UIImagePickerController和選擇器的委託的類。當機械手完成後,我嘗試推出另一名來自MainCameraTabController不同的視圖控制器,但我得到的錯誤,
*** 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。不知道爲什麼會這樣。