Uitableviewcontroller (Table View Controller) inherits from Uiviewcontroller, with a tableviewSelf.view is not UIView but UITableView .DataSource and delegate you are self (uitableviewcontroller) by defaultonly need to establish uitableviewcontroller subclass during development
TableView Edit
TableView Edit: Cell additions, deletionsUse the scene: Delete a downloaded video and delete the contact. insert a new chat record, etc.
Steps to edit 1, self let TableView in the editing state
//editbuttonitem corresponds to the corresponding method of the internal according to the state of the click button through the setediting:animtated: method to control whether the table view into the editing stateself.navigationItem.rightBarButtonItem = Self.editbuttonitem;2, specify tableview those lines can be edited
3. Specify TableView edit style (add, delete)
4. Edit complete (first manipulate data source, modify 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. The data of the corresponding row should be deleted first//2. Delete the corresponding row cells from the table view[Self.datasource RemoveObjectAtIndex:indexPath.row]; [TableView Deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationmiddle]; } 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 now//2, create the corresponding object Indexpath//3. Insert the corresponding row according to the position of the Indexpath in the table view[Self.datasource AddObject:@"the newly inserted data"]; Nsindexpath*insertpath = [Nsindexpath indexPathForRow:self.datasource.count-1Insection:0]; [TableView Insertrowsatindexpaths:@[insertpath] withrowanimation:uitableviewrowanimationmiddle]; } }
This method will be used when the table is dragged,
When the table is in the editing state, you can set the appropriate table to be edited with the following methods
UITableView Table View Editing