Customizing self.editButtonItem with Check and UnCheck- HELP

余生长醉 提交于 2019-12-02 19:44:28

问题


So with regards to the rightBarButtonItem . I have

self.navigationItem.rightBarButtonItem = self.editButtonItem;

When I press Edit, I get animation and a vertical stripe on the left side of each TableViewCell. When I click that stripe, the Delete button appears on the right side of THAT tableViewCell.

I want to do two things.

  1. Rename that 'Delete' to 'Check'
  2. If it is checked, it should display 'Uncheck' to be tapped.

I would appreciate any help on that..

:)


回答1:


Implement tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: in your table view delegate.




回答2:


For the second part of the answer I did this.

if (editingStyle == UITableViewCellEditingStyleDelete) {

 UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

 if (selectedCell.accessoryType == UITableViewCellAccessoryNone)
 {
     selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
 }
 else 
     if (selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
     {
         selectedCell.accessoryType = UITableViewCellAccessoryNone;
     }

}   

and

- (NSString *) tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

if (selectedCell.accessoryType == UITableViewCellAccessoryNone)
{

    return (@"Check");
}
else 
    if (selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
    {

        return (@"UnCheck");
    }

}


来源:https://stackoverflow.com/questions/6219289/customizing-self-editbuttonitem-with-check-and-uncheck-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!