Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

ios - How to detect edit mode on iPhone UITableView

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.by/It0

From the docs, it looked like if I implemented :

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

then I could detect it (although from the name of the method, I wouldn't think that). This proved not to work.

Any ideas on detecting this? The reason I want to is I want to hook up a "Delete all" button in the upper left hand corner when in delete mode.

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...