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!
If you want the action happen only when you tap the tab bar you can use the TabBarController delegate method :
Alternatively you can check which TabBarItem is selected :
NB : Remeber to set the UITabBarController delegate 😉