TableView implemented methods no grouping of cells
#pragma mark-table View data source-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{ return self.contacts.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ //1. Create cell Mjcontactcell *cell = [Mjcontactcell Cellwithtableview:tableview]; 2. Set the cell data cell.contact = Self.contacts[indexpath.row]; return cell;}
Refresh of TableView:
* Local Refresh (use premise: Before and after the refresh, the number of model data is unchanged)
-(void) Reloadrows: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;
* Local deletion (use premise: number of model data reduction = = Indexpaths length)
-(void) Deleterowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;
The left swipe calls the Commiteditingstyle method Commiteditingstyle to determine whether to add or remove
#pragma Mark-tableview Proxy Method/** * If this method is implemented, it automatically realizes the function of sliding deletion * Click the delete button will call * Commit an edit operation will be called (action: delete \ Add) * @param editingsty Le edit behavior * @param indexpath operation line number */-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelledit Ingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{if (Editingstyle = = Uitableviewcelleditingstyledelete) {//Submit a Delete action//1. Delete model data [self.contacts removeObjectAtIndex:indexPath.ro W]; 2. Refresh the table//partially refresh some rows (using the premise: the number of rows in the model data is constant) [Self.tableview Deleterowsatindexpaths:@[indexpath] Withrowanimation:ui Tableviewrowanimationtop]; 3. Archive [Nskeyedarchiver archiveRootObject:self.contacts Tofile:mjcontactsfilepath]; } else if (Editingstyle = = Uitableviewcelleditingstyleinsert) {//1. Modifying model data Mjcontact *contact = [mjcontact ALLOC] init]; Contact.name = @ "Jack"; Contact.phone = @ "10086"; [Self.contacts insertobject:contact AtIndex:indexPath.row + 1]; 2. Refresh Table Nsindexpath *nextpath = [Nsindexpath IndexPathForRow:indexPath.row + 1 insection:0]; [Self.tableview Insertrowsatindexpaths:@[nextpath] withrowanimation:uitableviewrowanimationbottom];//[ Self.tableview Reloaddata]; }}
Let TableView into edit state
[Self.tableview setediting:!self.tableview.isediting Animated:yes];
When the Editstyleforrowatindexpath is implemented, this method is called when the edit is clicked, which asks the state of the edit
/** * When TableView enters the edit state, it is called, asking what action each row will take (add \ Delete) */-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) indexpath{ return indexpath.row%2? Uitableviewcelleditingstyledelete:uitableviewcelleditingstyleinsert;}