1.在APPDelegate创建一个Nav,作为主Nav:
//.h @property (strong, nonatomic) LoginController *login_ctr; @property (strong, nonatomic) UINavigationController *login_nav; //.m self.login_ctr = [[LoginController alloc] init]; self.login_nav = [[UINavigationController alloc] initWithRootViewController:self.login_ctr]; self.window.rootViewController = self.login_nav;
2.在Login界面创建tab控制器,并添加各个子Nav:
HomeController *home_ctr = [[HomeController alloc] init]; home_ctr.title = @"首页"; UINavigationController *home_nav = [[UINavigationController alloc] initWithRootViewController:home_ctr]; DeviceController *device_ctr = [[DeviceController alloc] init]; device_ctr.title = @"设备列表"; UINavigationController *device_nav = [[UINavigationController alloc] initWithRootViewController:device_ctr]; UITabBarController *rootTabbarCtr = [[UITabBarController alloc] init]; NSArray *nav_views = @[home_nav,device_nav]; [rootTabbarCtr setViewControllers:nav_views]; [self.navigationController pushViewController:rootTabbarCtr animated:YES];
3.在需要返回最上层Login界面时调用:
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [app.login_nav popToRootViewControllerAnimated:YES];