2012-10-22 73 views
0

我有一個viewController,當我移動到應用程序中的另一個選項卡時,我想讓他彈出。我的問題是,當我在這個視圖中時,我有一個用於添加ABPeoplePickerNavigationController的人的「加號」按鈕,當人員選擇器變爲活動狀態時,視圖也會彈出,所以當我完成選擇應用程序的人員時,因爲它沒有任何意見可以回來。只有當特定視圖不出現時才彈出視圖控制器

這是viewWillDisappear:

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

我怎樣才能解決呢?

新代碼:

- (void)viewWillDisappear:(BOOL)animated 
{ 
    NSArray *controllers = self.darioTabController.childViewControllers; 
    UIView *v; 

    for (UIViewController *vc in controllers) 
    { 
     if ([vc isKindOfClass:[@"ModalPresnterViewController" class]]) // or even [ABPeoplePickerNavigationController class] 
     { 
      v = vc.view; 
     } 
     else 
      [self.navigationController popViewControllerAnimated:YES]; 
    } 
} 

謝謝!

回答

0

如果你想要的操作,只有當你點擊就可以使用TabBarController委託方法的標籤欄發生:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    //The user click on the item corresponding to ABPeoplePickerNavigationController 
    if([viewController isKindOfClass:[ABPeoplePickerNavigationController class]]) 
    { 
    //Do something if you cant 
    } 
    else // The user click on an other view controller (pop the ABPeoplePickerNavCtrl) 
    { 
    [yourController.navigationController popViewControllerAnimated:YES]; 
    } 
} 

或者可以查看哪個TabBarItem選擇:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    //Check if the selected view controller (ABPeopleNavCtrl) 
    if(tabBarController.selectedIndex == indexOfTheABPeoplePickNavigationController) 
    { 

    } 
    else // Else the user tap on an other item, so pop the controller you want 
    { 
    [theViewControllerToPop.navigationController popViewControllerAnimated:YES]; 
    } 
} 

注意:記住設置UITabBarController代理;)

+0

我怎樣才能知道當前顯示的視圖控制器是ABPeoplePick erNavigationController? –

+0

我編輯了我的回覆來回答你的問題;) – Ashbay

+0

這不適合我,因爲我不希望它只在移動到另一個tabBar時彈出,我希望它隨時彈出,除非打開ABPeoplePickerNavCon。我編輯了我的代碼,請檢查它。 –

相關問題