//要求委托方的编辑风格在表视图的一个特定的位置。
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//默认没有编辑风格
UITableViewCellEditingStyle result = UITableViewCellEditingStyleNone;
if ([tableView isEqual:_tableView])
{
//设置编辑风格为删除风格
result = UITableViewCellEditingStyleDelete;
}
return result;
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
//设置是否显示一个可编辑视图的视图控制器。
[super setEditing:editing animated:animated];
//切换接收者的进入和退出编辑模式。
[self.tableView setEditing:editing animated:animated];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//请求数据源提交的插入或删除指定行接收者。
if (editingStyle ==UITableViewCellEditingStyleDelete)
{ //如果编辑样式为删除样式
if (indexPath.row<[self.arrayShareList count])
{
//移除数据源的数据
[self.arrayShareList removeObjectAtIndex:indexPath.row];
//移除tableView中的数据
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
网友评论