以下是代码:
-(void)buttonEditPressed:(id)sender{
if(_tableView.isEditing){
[_tableView setEditing:NO animated:YES];
[_buttonEdit setTitle:@"Edit" forState:UIControlStateNormal];
} else {
[_tableView setEditing:YES animated:YES];
[_buttonEdit setTitle:@"Done" forState:UIControlStateNormal];
}
[_tableView reloadData];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
DLog(@"");
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Delete the rows at the Indexpath.
//edit data model
[_tableView reloadData];
}
结果如下:
滑动删除有效。然而,当按下编辑按钮时,单元格向右动画显示左侧红色删除按钮的空间,但该按钮永远不会出现!
我该怎么办?