Reputation: 345
In delegate class I wrote the code as follows
- (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];
}
but generateFirstScreen works fine but removeFirstScreen gives an exception Please help me.
Upvotes: 1
Views: 448
Reputation: 6323
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];
}
Upvotes: 0
Reputation: 2722
Don't remove a screen if you're not sure it's added to a view, otherwise you get a crash.. you can specify a tag to this view and check the subviews of the main view to check whether your view is in there somewhere..
Upvotes: 1
Reputation: 3234
Specify exception...
Without addSubview how can you remove it from super. Do you want to use popViewController.?
Again you are allocating firstScreen only once & releasing it twice..!
Upvotes: 1