UITableview edit/done button

前端 未结 3 1066
Happy的楠姐
Happy的楠姐 2020-12-28 18:11

I have a tableview and navigation bar on the top.

I have a Edit button on the left of my navigation bar with the following line of code.

self.navig         


        
3条回答
  •  被撕碎了的回忆
    2020-12-28 18:45

    The button stops committing the changes to your controller class once you override it's default action with self.editButtonItem.action = @selector(editClicked:);

    What you should do is override UIViewController's setEditing method in your own controller class:

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated];
    
        if(editing == YES) 
        {
            // Your code for entering edit mode goes here
        } else {
            // Your code for exiting edit mode goes here
        }
    }
    

    You also need to set your UIBarButtonItem to "Edit" in storyboard or if you prefer doing it in code use the following:

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

    editButtonItem is a helper property already set by the system for your comfort.

提交回复
热议问题