UITableView in edit mode - 'Edit' button doesn't change status

前端 未结 3 954
自闭症患者
自闭症患者 2021-02-08 04:41

I have a UIViewController class, with a tableView. In viewDidLoad:

UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButton         


        
相关标签:
3条回答
  • 2021-02-08 05:28

    Why not use -editButtonItem of UIViewController directly ? And override -setEditing:animated: method.

    // Assign the system's edit button, 
    // it will change style when different edit status.
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    // The editButtonItem will invoke this method.
    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
    
        if (editing) {
             // Execute tasks for editing status
        } else {
             // Execute tasks for non-editing status.
        }
    }
    
    0 讨论(0)
  • 2021-02-08 05:30

    It's because you're only setting the style of the button (not its text) when you switch modes. You need to do this (or equivalent):

    -(void)toggleEditMode{
        self.navigationItem.rightBarButtonItem.title = self.tableView.editing ? @"Done" : @"Edit";
    
    0 讨论(0)
  • 2021-02-08 05:38

    You sure callsArray is not empty ?

    Place a breakpoint inside toggleEditMode and see what happens there.

    Edit

    Ok, after understanding your question, have a look at this thread

    0 讨论(0)
提交回复
热议问题