How can I remove the present view when I have added more than one subView ?

Posted by srikanth rongali on Stack Overflow See other posts from Stack Overflow or by srikanth rongali
Published on 2010-04-29T05:35:12Z Indexed on 2010/04/29 5:37 UTC
Read the original article Hit count: 222

How can I remove the present view when I touched the close button.
I did [self.view removeFromSuperView] when I added only one subView. It worked. But, I have now added another subView to the previous subView. I need to to get the parent view . How can I do it. My code of adding the subView is here. When I did the following only one view is removed.

//FirstViewController: UIViewController
-(void)libraryFunction:(id)sender
{
    LibraryController *libraryController = [[LibraryController alloc]init];
    [self.view addSubview:libraryController.view];
}

//LibraryController: UIViewController
-(void)viewDidLoad{
    RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.navController = aNavigationController;
    [aNavigationController release];
    [rootViewController release];
    [self.view addSubview:navController.view];
}

//RootViewController: UITableViewController
- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(close:)];
}

-(void)close:(id)sender
{
    [self.view removeFromSuperview];
}  

Thank You.

© Stack Overflow or respective owner

Related posts about cocoa-touch

Related posts about iphone-sdk-3.0