iOS 8 TableviewCell侧滑出现更多Button

来源:互联网 发布:淘宝直通车课程 编辑:程序博客网 时间:2024/06/05 03:31

原创Blog,转载请注明出处
blog.csdn.net/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里,加入想要的执行逻辑就可以了。

1 0
原创粉丝点击