系统自带的功能可以左滑删除,可以全部一起编辑。这个是左边滑动删除。
@property (nonatomic, strong) NSMutableArray * dataArray;
- (instancetype)init{
if(self= [superinit]){
self.dataArray = [NSMutableArray arrayWithObjects:@"22pw",@"22oppjhjjopw",@"22oppjhjjopw", nil];
}
return self;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
staticNSString*MyIdentifier =@"cellzz";
BGAddressBookFirstTableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:MyIdentifier];
if(!cell) {
cell = [[BGAddressBookFirstTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.leftFirsLabel.text=self.dataArray[indexPath.row];
returncell;
}
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[selfdeleteSelectIndexPath: indexPath];
}
}
- (void)deleteSelectIndexPath:(NSIndexPath *)indexPath{
[self.dataArrayremoveObjectAtIndex:indexPath.row];
// [self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
// [self.tableView endUpdates];
}
#pragma mark 让tableView处于编辑状态(设置可以进行编辑)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[supersetEditing:editinganimated:animated];
[self.tableView setEditing:!self.tableView.isEditing animated:YES];
}
#pragma mark 设置可以进行编辑
-(BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath{
return YES;
}
#pragma mark 设置编辑的样式
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
return UITableViewCellEditingStyleDelete;
}
#pragma mark 修改编辑按钮文字
-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath{
return BGLocaltring(@"Delete");
}