iOS中tableview 中不同cell分别自定义左滑选项

项目中需要展现用户的家庭成员,第一行是用户自己,下面分别是用户的家庭成员。成员可被编辑、删除,但用户本身只能编辑资料,不可被删除。可以利用UITableViewDelegate中的
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath方法对不同的cell自定义左滑动作。

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
    [self deleteMember:indexPath];
}];//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义
    UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
    [self deleteMember:(NSIndexPath *)indexPath];

}];
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
    [self editMember:(NSIndexPath *)indexPath];
}
if (indexPath.row>0) {
return @[deleteRoWAction, editRowAction];//最后返回这俩个RowAction 的数组
}
else{
    return @[editAction];//row=0时只返回编辑按钮
}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容