1. Delete:
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath
{
If (editingStyle = UITableViewCellEditingStyleDelete)
{
NSLog (@"....");
NSUInteger row = indexPath. row;
[Self. editArray removeObjectAtIndex: row];
[TableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation :( UITableViewRowAnimationTop)];
}
// Collect data updates
// [Self replaceCurrentViewData: self. editArray];
}
Implement the above functions
2; Mobile:
-(Void) tableView :( UITableView *) tableView moveRowAtIndexPath :( NSIndexPath *) sourceIndexPath toIndexPath :( NSIndexPath *) destinationIndexPath
{
If (sourceIndexPath! = DestinationIndexPath)
{
Id object = [self. editArray objectAtIndex: sourceIndexPath. row];
[Object retain];
[Self. editArray removeObjectAtIndex: sourceIndexPath. row];
If (destinationIndexPath. row> [self. editArray count])
{
[Self. editArray addObject: object];
}
Else {
[Self. editArray insertObject: object atIndex: destinationIndexPath. row];
}
[Object release];
}
// [Self replaceCurrentViewData: self. editArray];
}
3: insert
This is similar to deleting a row. To achieve this, click the plus sign (+.
3.1 first modify UITableViewCellEditingStyleDelete in the editingStyleForRowAtIndexPath method to UITableViewCellEditingStyleInsert
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath
{
If (editingStyle = UITableViewCellEditingStyleDelete)
{
NSLog (@"....");
NSUInteger row = indexPath. row;
[Self. editArray removeObjectAtIndex: row];
[TableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation :( UITableViewRowAnimationTop)];
}
Else
{
NSArray * insertIndexPaths = [NSArray arrayWithObjects: indexPath, nil];
// Similarly, add the data to the list and use the row
[Self. list insertObject: @ "newly added row" atIndex: row];
[TableView insertRowsAtIndexPaths: insertIndexPaths withRowAnimation: UITableViewRowAnimationRight];
}
// Collect data updates
// [Self replaceCurrentViewData: self. editArray];
}
4: Mark:
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath
{
UITableViewCell * oneCell = [tableView cellForRowAtIndexPath: indexPath];
If (oneCell. accessoryType = UITableViewCellAccessoryNone ){
OneCell. accessoryType = UITableViewCellAccessoryCheckmark;
} Else
OneCell. accessoryType = UITableViewCellAccessoryNone;
[TableView deselectRowAtIndexPath: indexPath animated: YES];
}
Else {
// We insert a row at the position of the selected row, so the indexPath parameter is directly used.
NSArray * insertIndexPaths = [NSArray arrayWithObjects: indexPath, nil];
// Similarly, add the data to the list and use the row
[Self. list insertObject: @ "newly added row" atIndex: row];
[TableView insertRowsAtIndexPaths: insertIndexPaths withRowAnimation: UITableViewRowAnimationRight];
}