iphoneiosxcode4.2uitableviewnavigationitem

UITableViewController NavigationItem button issues


I'm having issues in setting navigation buttons on my UITableViewController! this controller is inside a UINavigationController.

I've following view controller:

@interface SettingsViewController : UITableViewController<UITextFieldDelegate, UINavigationControllerDelegate> {

   }
...........

@end

and in implementation file:

- (void)viewDidLoad 
     {
          self.navigationItem.rightBarButtonItem = self.editButtonItem;
     }

I'm adding navigation button items programmatically.

edit:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];
    //[self.navigationItem setHidesBackButton:editing animated:YES];

    if (!editing) 
    {
     self.navigationItem.leftBarButtonItem = nil;
        [self save];
    }
    else 
    {
        UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Cancel:)];
        self.navigationItem.leftBarButtonItem = cancelButtonItem;
        cancelButtonItem = nil;
    }
}

-- above edit function seems to be working fine in terms of setting navigation buttons

cancel:

- (IBAction)Cancel:(id)sender {
    //cancel
    self.navigationItem.rightBarButtonItem = self.editButtonItem; --> this is not setting edit button.
    self.navigationItem.leftBarButtonItem = nil;
}

-- but clicking on cancel is not replacing navigationitem right-barbutton 'Done' with 'Edit' even though I'm doing this in Cancel method as shown above.

whats wrong with this code?

when I debug, I can't see following in debug area:

po self.navigationItem

any idea why?

Thanks in advance,

Rama


Solution

  • Simple, set editing to NO:

    - (IBAction)Cancel:(id)sender {
        //cancel
        self.editing = NO; //--> This is the trick!!!!!!
        self.navigationItem.rightBarButtonItem = self.editButtonItem; 
        self.navigationItem.leftBarButtonItem = nil;
    }