1

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.

Venkat
  • 343
  • 1
  • 7
  • 17

3 Answers3

1

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..!

hp iOS Coder
  • 3,230
  • 2
  • 23
  • 39
  • As BobDev said you can remove view only if you have added it. If you want to remove firstScreen which you have pushed to UINavigationController then u have to use popViewController. So i dont suggest you to write addSubview somewhere in code – hp iOS Coder Mar 27 '12 at 10:33
  • 1
    Also dont release firstScreen in removeFirstScreen method coz you have released it already in generateFirstScreen method – hp iOS Coder Mar 27 '12 at 10:36
1

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..

Bob de Graaf
  • 2,630
  • 1
  • 25
  • 43
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];
}
Narayana Rao Routhu
  • 6,303
  • 27
  • 42