Search code examples
iphoneuinavigationcontrollerdismissrootviewpoptoviewcontroller

pushViewController and popToRootViewController


My application is using pushViewController to show the navigation controller modally

 [navigationController pushViewController:_viewController animated:YES];

Navigation Controller has done button

UIButton* backButton = [UIButton buttonWithType:101]; 
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];

UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

self.navigationItem.leftBarButtonItem = backItem;
[backItem release];

When done button is pressed I want that it should navigate back to main window

-(void) dismissView: (id)sender

{
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

But when I press on done button nothing happens. Why is that?


Solution

  • Please NSLog in your dissmissView

    -(void) dismissView: (id)sender
    
    {
       NSLog(@"Hii....");
        [self.navigationController popToRootViewControllerAnimated:YES];
    //[self.navigationController popToViewController:_viewController animated:YES];
    
    }
    

    or debug the app with break point.