原创Blog,转载请注明出处
blog.youkuaiyun.com/hello_hwc
效果:
iOS 8之前,需要自己定制UITableviewcell来实现,IOS 8以后,只需要添加两个简单的代理函数即可。
//允许cell进入编辑状态
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//这里可以什么都不做
}
//定制tableviewCell
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction * action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
//Action 1
}];
UITableViewRowAction * action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
//Action 2
}];
action2.backgroundColor = [UIColor greenColor];
return @[action1,action2];
}
在UITableViewRowAction的block里,加入想要的执行逻辑就可以了。
iOS表格视图编辑操作
本文介绍如何在iOS中为UITableView配置编辑操作。对于iOS 8及更高版本,仅需实现两个代理方法即可轻松实现单元格的编辑功能,如删除和更多选项。
558

被折叠的 条评论
为什么被折叠?



