PopToRootViewController fails when calling UITabBarControllerDelegate

I have UITabBarControllerwith 4 UINavigationControllers. I implemented the delegate method didSelectViewControlleras follows:

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([viewController isKindOfClass:[UINavigationController class]]) {
    [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];

}
}

Failure, when it NavigationControlleris at level 2 after didSelectRowAtIndexPath, pushes a new viewController stack onto the stack.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Navigation logic may go here. Create and push another view controller.

RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

// ...    
detailViewController.title = [self.temp objectAtIndex:indexPath.row];
detailViewController.sort = self.title;

// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

}

Of course, the debugger with it turned on NSZombiesdoes not give feedback.

However, if I add the value keep to detailViewController alloc;

RootViewController *detailViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] retain];

It works, but a memory leak.

Any ideas what is wrong, how to fix what is happening?

+3
source share
1 answer

I have a similar scenario, and I came up with the following solution.

, UITabbarController 4 UINavigationControllers.

UINavigationController AppDelegate.h.

@property (strong, nonatomic) UINavigationController *navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions         (NSDictionary *)launchOptions
{
 //Override point for customization after application launch.
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];

return YES;
}

, RootViewController,

#import "AppDelegate.h"

[((AppDelegate *)[[UIApplication sharedApplication] delegate]).navigationController popToRootViewControllerAnimated:YES];

, .

0

All Articles