0

I have a viewController that I want him to pop when I moving to another tab in the application. My problem is that when I'm inside this view I have a "plus" button for adding people with ABPeoplePickerNavigationController, than when the people picker becomes active, the view is popping as well, so when I finished of choosing people the application crushes, because it don't have any view to come back to.

this is the viewWillDisappear:

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

How can I solve it?

New code:

- (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];
    }
}

Thanks!

4

1 回答 1

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 委托;)

于 2012-10-22T10:05:23.083 回答