2011-03-17 85 views
1

這是我的目標: 我想從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。不知道爲什麼會這樣。

回答

0

由於動畫關閉視圖時,需要延遲動畫才能執行下一個動畫。您可以通過將animated設置爲NO來解決此問題。這將切斷動畫並立即執行下一個動畫。

對於意見,我有類似的經驗,我所做的是切換視圖的順序。我發起了這樣一個觀點,即我想在選取器之後首先顯示,在viewDidload方法中,我創建並顯示選取器,因此在選取器被解散後,它將顯示我想要的視圖。如果你想讓它們看起來很自然,你可以隨時使用視圖的hidden屬性來平滑流動。