iOS development often occurs when a cell requires multiple buttons, which are generally thought to be imported into a third-party framework. But in fact, after iOS 8, the system provides uitableviewrowaction and a new delegate approach, making it easy to customize some operations. Buttons such as top, delete, modify, more, favorites, etc.
-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) indexpath{
Add a sticky button
Uitableviewrowaction *toprowaction = [Uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@ "pinned" handler:^ (uitableviewrowaction *action, Nsindexpath *indexpath) {
NSLog (@ "Click on the top button");
1. Update data
[_diarary ExchangeObjectAtIndex:indexPath.row withobjectatindex:0];
2. Update UI
Nsindexpath *firstindexpath = [Nsindexpath indexpathforrow:0 inSection:indexPath.section];
[TableView Moverowatindexpath:indexpath Toindexpath:firstindexpath];
}];
Toprowaction.backgroundcolor = [uicolor redcolor];//customizable button color
}
This allows you to add any number of buttons. To make sure this code takes effect, you also need to implement the Commiteditingstyle delegate method, even if nothing is written.
-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{
}
Remember: When you add multiple groups of buttons, the system comes with a delete button that does not exist and you need to rewrite it yourself.
The cell Multi-button for iOS development