1. For TableView, the view of each item is basically the same. The only difference is data.
iOS provides a way to cache views and data. In-UITableViewCell *) TableView:cellforrowatindexpath:
Create a label for the cache static nsstring *[email protected] "celltable"; First get UITableViewCell UITableViewCell *cell=[tableview Dequeuereusablecellwithidentifier:id] from the cache; If not, the code is created. if (cell==nil) { Cell=[[uitableviewcell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier : ID]; }
2
Create a system-supplied icon for each item to the right Cell.accessorytype=uitableviewcellaccessorycheckmark;
3. Modify the display of an item by animation
[TableView Reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationleft];
4. Delete an item by animation
[Self.tableview deleteRowsAtIndexPaths:self.indexPaths Withrowanimation:uitableviewrowanimationleft];
CSZViewController.h The overall code is as follows: declares TableView protocol and data source
#import <UIKit/UIKit.h> @interface Cszviewcontroller:uiviewcontroller <uitableviewdatasource, Uitableviewdelegate> @property (Weak, nonatomic) Iboutlet UITableView *tableview;-(ibaction) Trashclick: (ID) sender ; @end
CSZVIEWCONTROLLER.M the TableView code is as follows:
#pragma mark-datasource#pragma mark number of rows per column-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: ( Nsinteger) section{return self.array.count;} #pragma mark creates view-(UITableViewCell *) TableView for each line: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//Create a label for the cache static NSString *[email protected] "celltable"; First get UITableViewCell UITableViewCell *cell=[tableview Dequeuereusablecellwithidentifier:id] from the cache; If not, the code is created. if (cell==nil) {Cell=[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; } Cell.textlabel.text=self.array[indexpath.row]; [email protected] "description ..."; if ([Self.deletearr ContainsObject:cell.textLabel.text]) {//Create a system-supplied icon to the right of each item Cell.accessorytype=uitablevi Ewcellaccessorycheckmark; }else {cell.accessorytype=uitableviewcellaccessorynone; } return cell; } #pragma mark-uitableviewdelegate#pragma maRK Click on each item call-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{[TableView Deselectrowatindexpath:indexpath Animated:yes]; if ([Self.deletearr Containsobject:self.array[indexpath.row]]) {[Self.deletearr removeobject:self.array[indexpath. Row]]; [Self.indexpaths Removeobject:indexpath]; }else {[Self.deletearr addobject:self.array[indexpath.row]]; [Self.indexpaths Addobject:indexpath]; } [TableView Reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationleft];} #pragma mark returns height per row-(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{ return 70;}