Search code examples
iphoneobjective-ciosuinavigationcontroller

UINavigationController back and close button


I have a navigation controller. The controller works well and shows me the back button for go back to the window. But when I add this code for add the close button:

- (void)viewDidLoad 
{
  [super viewDidLoad];

  UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Chiudi" 
                                  style:UIBarButtonItemStylePlain target:self
                       action:@selector(dismissModalViewControllerAnimated:)];          
  
  self.navigationItem.rightBarButtonItem = doneButton;
  
  [doneButton release];

}

...then the back button disappears, and I can only see the close button. Why?


Solution

  • THE PROBLEM was in

     dismissModalViewControllerAnimated 
    

    I HAD TO USE

     [self.navigationController dismissModalViewControllerAnimated:YES];     
     [self.navigationController popToRootViewControllerAnimated:NO];