Self.navigationItem.rightBarButtonItem = Self.editbuttonitem;
-(void) setediting: (BOOL) editing animated: (BOOL) animated{ [Super setediting:editing animated: Animated]; [Self.countriestableview setediting:editing animated:animated];}
-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) indexpath{ if (Editingstyle = = Uitableviewcelleditingstyledelete) { * delegatecountry = Self.countries[indexpath.row]; [Self.countries Removeobject:delegatecountry]; [Self.countriestableview Deleterowsatindexpaths:[nsarray Arraywithobject:indexpath] WithRowAnimation: Uitableviewrowanimationautomatic];} }
Insert (the default editing style is Uitableviewcelleditingstyledelete), so add the insert style.
-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath * ) indexpath{ if ((indexpath.row%20) { return Uitableviewcelleditingstyleinsert; } return Uitableviewcelleditingstyledelete;}
}Else if(Editingstyle = =Uitableviewcelleditingstyleinsert) {Country* Copiedcountry =Self.countries[indexpath.row]; Country* Newcountry =[[Country alloc] init]; Newcountry.name=Copiedcountry.name; Newcountry.flag=Copiedcountry.flag; Newcountry.capital=Copiedcountry.capital; Newcountry.motto=Copiedcountry.motto; [Self.countries insertobject:newcountry AtIndex:indexPath.row+1]; [Self.countriestableview insertrowsatindexpaths:[nsarray Arraywithobject:[nsindexpath IndexPathForRow: Indexpath.row+1InSection:indexPath.section]] Withrowanimation:uitableviewrowanimationright]; }
Re-order
-(BOOL) TableView: (UITableView *) TableView Canmoverowatindexpath: (Nsindexpath *) indexpath{ return YES;}
-(void) TableView: (UITableView *) TableView Moverowatindexpath: (Nsindexpath *) Sourceindexpath Toindexpath: ( Nsindexpath *) destinationindexpath{ [Self.countries exchangeObjectAtIndex:sourceIndexPath.row WithObjectAtIndex:destinationIndexPath.row]; [Self.countriestableview reloaddata];}
Edit Uitableviewcell--editing