@interface Viewcontroller () <UITableViewDelegate,UITableViewDataSource>
@property (Nonatomic,strong) Nsmutablearray *datasourcearray;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.datasourcearray = [Nsmutablearray arraywithobjects:@ "A", @ "B", @ "C", @ "D", @ "E", @ "F", @ "G", @ "H", @ "I", @ "J", @ "K", @ "L", @ "M", nil];
UITableView *tableview = [[UITableView alloc]initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, self.view.frame.size.height) Style:uitableviewstyleplain];
Tableview.delegate= self;
Tableview.datasource = self;
Open Edit State
[TableView Setediting:yes Animated:yes];
[Self.view Addsubview:tableview];
}
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
return self.dataSourceArray.count;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
static NSString *cellidentifier = @ "Cell";
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];
if (!cell)
{
cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier];
}
Cell.textLabel.text = Self.datasourcearray[indexpath.row];
return cell;
}
Each of these two parameters is written in its own state, and the two are written together as the front circled multi-select state
-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath
{
return Uitableviewcelleditingstyledelete | Uitableviewcelleditingstyleinsert;
}
Click cell Select to add something to your data source array
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {
}
This is the thing that cancels the click of the cell to delete your data source
-(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: (Nsindexpath *) indexpath{
}
Delete your cell and your data source items according to the above two methods remember to refresh the table
The effect of the implementation
Multi-select mode for Tabelview