How to detect edit mode on iPhone UITableView

前端 未结 5 1324
小蘑菇
小蘑菇 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:27

    It is probably not working as you expect because willBeginEditingRowAtIndexPath: is called before the editing starts.

    If you want to check while in another method you need the editing property:

    @property(nonatomic, getter=isEditing) BOOL editing
    

    If you want to do something when the 'Edit' button is pressed you need to implement the setEditing method:

     - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    

    Which you'll find in UIViewController. (Well, that's the most likely place; there are others.)

    Swift Use below code accordingly:

    open var isEditing: Bool // default is NO. setting is not animated.
    
    open func setEditing(_ editing: Bool, animated: Bool)
    

提交回复
热议问题