您的位置:首页 > 其它

4.8 Enabling Swipe Deletion of Table View Cells

2013-11-28 10:38 337 查看
你是否曾经在tableView列表中删除某些行,你是怎么删除的呢?

通过点击某个按钮,然后列表每一行的左边出来一个红色减号,点击然后右边出来一个删除按钮,然后删除?(这种情况时设置列表的editing属性来实现的)

当然了,还有一种情况是在这一行上划一下,然后就出来一个删除按钮,这功能是怎么实现的呢?

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

return UITableViewCellEditingStyleDelete;

}

-(void)setEditing:(BOOL)editing animated:(BOOL)animated

{

[super setEditing:editing animated:animated];//苹果说这个一定要写,删了不知会咋样,小例子没出现问题

[_tableView setEditing:editing animated:animated];

}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

if (editingStyle == UITableViewCellEditingStyleDelete) {

[tableRows removeObjectAtIndex:indexPath.row]; //先删除数据源里的数据,再从界面上删除

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: