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

前端 未结 3 945
自闭症患者
自闭症患者 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.
        }
    }
    

提交回复
热议问题