A. The process of execution
1,tableview into edit state
The user clicks on a button to let the program enter the editing state,
self.tableView.editing = YES;
2, ask TableView if the cell can be edited
TableView asks the DataSource agent to execute an agent method asking for the edit status of each line
i.e.-(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath//default Yes, i.e. at editing = yes, Default all rows can be deleted
3, ask TableView's edit type (delete or add)
TableView asks the editor status of each line of the delegate agent
i.e.-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath//Delete by default
Where Uitableviewcelleditingstyle is an enumeration type
typedef Ns_enum(Nsinteger, Uitableviewcelleditingstyle) {
Uitableviewcelleditingstylenone,
Uitableviewcelleditingstyledelete,
Uitableviewcelleditingstyleinsert
The};//system comes with three editing states
typedef ns_enum (Nsinteger, Uitableviewcelleditingstyle) {
Uitableviewcelleditingstylenone,
Uitableviewcelleditingstyledelete,
Uitableviewcelleditingstyleinsert
};
4,tableview Response Edit Operation
A proxy method is executed by DataSource to respond to an edit operation
i.e.-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath
Specific instructions
-(void) TableView: (uitableview *) TableView Commiteditingstyle: (Uitableviewcelleditingstyle ) Editingstyle Forrowatindexpath: (nsindexpath *) indexpath
{
if (Editingstyle = = Uitableviewcelleditingstyledelete) {// Perform delete operation
//1, First delete the data from the data source
//2. Visually removed, the data must be actually removed from the data source before it is deleted, or the program will crash (the first parameter in the following method is the nsarray type, which identifies the row to be deleted , and the element that holds the Nsindexpath object)
[_mytableview deleterowsatindexpaths: @[indexpath] withrowanimation: Uitableviewrowanimationleft];
// Note that the order of execution is not variable
/**
* Delete the entire section (logic is similar to deleting a row in the sections )
*/
//1, First delete data from the data source
//2, visually removed ( the first parameter in the following method is of type Nsindexset, which identifies the section to be deleted )
[_mytableview deletesections: [nsindexset indexsetwithindex: Indexpath. Section] withrowanimation:uitableviewrowanimationleft];
}
if (Editingstyle = = Uitableviewcelleditingstyleinsert) {// Perform add operation
///1, Add data from the data source location
///2, added visually (the first parameter of the following method is the established add position )
[_mytableview insertrowsatindexpaths: @[indexpath] withrowanimation: Uitableviewrowanimationleft]; // Add the current position at the point you clicked
//Customizable Nsindexpath object to make insertion position
}
}
The implementation principle and deletion of uitableview editing