How to change a UIBarButtonItem in a UINavigationBar

前端 未结 5 1732
醉酒成梦
醉酒成梦 2021-02-06 04:40

I\'m trying to set up a list of items that can be edited. I have a main view, with a UINavigationBar at the top and a UITableView directly under it. I\'d like to have my \"edit\

5条回答
  •  抹茶落季
    2021-02-06 05:08

    set up nav button in IB with the following linked in IB and create an outlet called editOutlet and and an action called editToggle in your header file and your method is as easy as this:

    -(IBAction) editToggle:(id) sender {
    
    if (self.tableViewOutlet.isEditing == NO) {
    
        self.editOutlet.title = NSLocalizedString(@"Done", @"Done");
        self.editOutlet.style = UIBarButtonItemStyleDone;
        [self.tableViewOutlet setEditing:YES animated:YES];
    
    }else {
        self.editOutlet.title = NSLocalizedString(@"Edit", @"Edit"); 
        self.editOutlet.style = UIBarButtonItemStylePlain;
        [self.tableViewOutlet setEditing:NO animated:YES];
    
        }
    }
    

提交回复
热议问题