How to disable uiviewcontroller / unload view on logout

I think this is a fairly common utility that I have seen in several applications. But after spending a couple of days, I'm still struggling with this. I have a structure similar to the following:

UITabBarController
-- UINavigationController1
 ---- UITableViewController1

-- UINavigationController2
---- UITableViewController2

Now I have an exit button on UITableViewController2. When I click on this exit button, I want everyone and any view manager to be freed, everyone looked without loading. Basically, start from scratch, like starting an application. I basically want viewDidLoad on each of these UITableViewController to be called again.

I tried the following method to call in my appdelegate when the exit action from UITableViewController2 was performed.

-(void) logout {
    for (UINavigationController* ctrl in self.tabBarController.viewControllers) {
        [ctrl popToRootViewControllerAnimated:NO];
        ctrl.visibleViewController.view = nil;
    }

[self.tabBarController.view removeFromSuperview];
[self.window addSubview:self.tabBarController.view];

}

But alas, this does not work?

, ? iOS4 iOS5 visibleViewController. . ?

: ARC

MBH

+5
3

for-loop , , , UINavigationController ( , ), .. , , . UITableViewControllers .

UINavigationControllers, tabbar-controller . IMHO, , UITabBarController.

UITabBarController. , tbh. , . , ., , . appdelegate , , logout() UITableViewController2, UITabbarController, UITableViewController2 -.

, , AppDelegate TabBar-Controller, self.window?

// manually create UITabBarController - AppDelegate holds instance
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    mytabcontroller=[[UITabBarController alloc] initWithNibName:@"foo" bundle:nil];
}

- (void) logout {
  [self.tabBarController.view removeFromSuperview];
  [mytabcontroller release];
  mytabcontroller=[[UITabBarController alloc] initWithNibName:@"foo" bundle:nil];
  [self.window addSubview:self.tabBarController.view];
}

, , .

+2

. , ( dealloc ).

+1

rootViewController - TableView. , popToRootViewController -.

, reset , .

+1

All Articles