在委托类中,我编写了如下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
[self generateFirstScreen];
[self removeFirstScreen]; // On login check implement this method or u can directly write the snippet here as well.
[self prepareControllersOnTabs]; //your tab controller code function
[self.window makeKeyAndVisible];
return YES;
}
-(void) removeFirstScreen
{
[firstScreen removeFromSuperView];
self.window.rootViewController = self.tabBarController;
[firstScreen release];
}
-(void) generateFirstScreen
{
FirstScreen *firstScreen = [[FirstScreen alloc]init];
[self.navigationController pushViewController:firstScreen animated:YES];
[firstScreen release];
}
但generateFirstScreen工作正常但removeFirstScreen给出了异常请帮帮我。
答案 0 :(得分:1)
指定例外...
如果没有addSubview,你怎么能从super中删除它。你想使用popViewController吗?
你再次只分配firstScreen一次&释放它两次..!
答案 1 :(得分:1)
如果您不确定它是否已添加到视图中,请不要删除屏幕,否则会出现崩溃...您可以为此视图指定标记并检查主视图的子视图以检查您的视图是否是在某处..
答案 2 :(得分:0)
your generateFirstScreen method Change like below
FirstScreen *firstScreen = [[FirstScreen alloc]initWithNibName:@"FirstScreen" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.objLogin];
// Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
//call this metod when ever u want tabbar
-(void)tabBarControllerView
{ [self.navigationController.view removeFromSuperview];
[self.navigationController.view setHidden:YES] ;
self.tabBarController.selectedIndex = 0;
self.tabBarController.view.hidden=NO;
[window addSubview:self.tabBarController.view];
}