Pergunta

i've developed an app for ios, using a uitabbar. In the tabbar i have some uitableview leading to some uiview. For example:

A:Tabbar button -> B:Table View -> C:View relative to the line of the table view hitten by the user

The normal behavior of the tabbar is that, if i click till the view i've indicated as "C", then click another Tabbar button and click back to the Tabbar button that i've indicated like "A", i find opened the view "C" instead of "B" (the table view called by the tabbar button). Now i'd like the tabbar leading always to its first view (in this case B, even if the user clicked until C) In order to do this, i use this code in my appdelegate, to be sure it have the same behavior even in the case of the "More Button".

UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController;

if ([viewController isKindOfClass:[UINavigationController class]]) {
    [tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];
}
if (tabBarController2.selectedIndex < 4) {
    [tabBarController2.moreNavigationController popViewControllerAnimated:NO];
}

Sometimes, when it try to pop, the app crash. What am i doing wrong?

The line

[tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];

fires this warning "AppDelegate.m:27:10: 'UIViewController' may not respond to 'popToRootViewControllerAnimated:'"

Foi útil?

Solução

One way i would suggest you is that, in your UIView viewWillDisapear method write following code:

[self.navigationController popToRootViewControllerAnimated:NO];

Outras dicas

popToRootViewControllerAnimated:

This is a method of UINavigationController class and you are using it for UITabBarController which is intern a subclass of UIViewController.

Try:

[(UINavigationController *)tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top