How to detect edit mode on iPhone UITableView

前端 未结 5 1307
小蘑菇
小蘑菇 2020-12-03 14:42

For my iPhone app, I have an editable (for delete) table view. I\'d like to be able to detect that the user has clicked the \"Edit\" button. See this image: http://grab.b

5条回答
  •  执笔经年
    2020-12-03 15:13

    That method tells you when a user is editing a Cell, not put the table into editing mode. There is a method called when editing mode is entered, to ask each cell if it can be edited:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    

    I don't think overriding setEditing:animated: makes sense, since you would have to subclass UITableView which is extra work and a class you need for no other reason, not to mention it would have to communicate the fact that editing had been turned on back to the controller.

    One other option is to simply add the Edit button yourself - it's a built in UIBarButtonSystemItem, you can add it and then have it call your own method in which you do something specific then call setEditing:animated: on the UITableView itself.

    The idea behind editing is that when editing is enabled, each cell is told to go to edit mode, and as asked if there are any specific editing controls that should be applied. So in theory there's no need to detect entry into editing mode beyond changing the appearance of cells. What are you trying to do when editing mode is entered?

提交回复
热议问题