Edit UITableView table view and uitableview
UITableViewController (Table view Controller) is inherited from UIViewController and comes with a tableViewself. view instead of UIView, but UITableViewdatasource and delegate. By default, you only need to create a UITableViewController subclass during the development of self (UITableViewController ).Edit tableView TableView Editing: cell addition and deletion scenarios: delete a downloaded video and contacts. Insert a new chat recordEdit procedure1. self: Make tableView editable
// The corresponding method corresponding to editButtonItem uses setEditing: animtated: method to control whether the table view enters the editing status self based on the status of the clicked button. navigationItem. rightBarButtonItem = self. editButtonItem; 2. Specify the rows in tableView that can be edited.
3. Specify the tableView editing style (add or delete)
4. Edit (operate the data source first and modify the UI)
// Override to support editing the table view. -(void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath {if (editingStyle = UITableViewCellEditingStyleDelete) {// Delete the row from the data source // 1. You should first Delete the data of the corresponding row // 2, and then Delete the cells of the corresponding row from the table view [self. datasource removeObjectAtIndex: indexPath. row]; [tableView deleteRowsAtIndexPaths: @ [indexPath] withRowAnimation: Paths];} else if (editingStyle = UITableViewCellEditingStyleInsert) {// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view // 1. Insert the corresponding object in the array // 2. Create the corresponding object indexPath // 3. According to the position of indexPath In the table view insert the corresponding row [self. datasource addObject: @ "newly inserted data"]; NSIndexPath * insertPath = [NSIndexPath indexPathForRow: self. datasource. count-1 inSection: 0]; [tableView insertRowsAtIndexPaths: @ [insertPath] withRowAnimation: UITableViewRowAnimationMiddle];}
This method is used when the table is dragged,
When the table is edited, you can use the following method to set whether the corresponding table is edited or not.