Set a button, click it to delete it, and move the sorted tableview as follows: move on the left, delete on the right
Move first:
Button to set ibaction
-(Ibaction) togglemove {[self. tableview setediting:!Self. tableview. Editing animated: Yes];If(Self. tableview. Editing) [self. navigationitem. rightbarbuttonitem settitle:@"Done"];Else[Self. navigationitem. rightbarbuttonitem settitle:@"Move"];}
Self.Tableview.The editing attribute is of the bool type, indicating the editing status of tableview.
Here, the button is set to two types of text, corresponding to different States.
Then implement three delegate methods:
-(Uitableviewcelleditingstyle) tableview :( uitableview * ) Tableview editingstyleforrowatindexpath :( nsindexpath * ) Indexpath { Return Uitableviewcelleditingstylenone ;} -(Bool) tableview :( uitableview * ) Tableviewcanmoverowatindexpath :( nsindexpath * ) Indexpath { Return Yes ;} -( Void ) Tableview :( uitableview *) Tableviewmoverowatindexpath :( nsindexpath * ) Fromindexpath toindexpath :( nsindexpath * ) Toindexpath {nsuinteger fromrow = [Fromindexpath row]; nsuinteger torow = [Toindexpath row]; ID Object = [List objectatindex: fromrow]; [list removeobjectatindex: fromrow]; [list insertobject: Object Atindex: torow];}
Deleting is simpler.
The action of the button is the same as the preceding one,
You only need to implement one delegate method:
-(Void) Tableview :( uitableview *) Tableviewcommiteditingstyle :( uitableviewcelleditingstyle) editingstyleforrowatindexpath :( nsindexpath*) Indexpath {nsuinteger row=[Indexpath row]; [self. List removeobjectatindex: Row]; [tableview deleterowsatindexpaths: [nsarray arraywithobject: indexpath] withrowanimation: uitableviewrowanimationautomatic];}
You can also combine the two to implement the above 4-brother delegation method. Note that in the editingstyleforrowatindexpath method, uitableviewcelleditingstyledelete is returned.
As follows: