iOS 8 TableviewCell侧滑出现更多Button



OS 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里,加入想要的执行逻辑就可以了。


http://linglong117.blog.163.com/blog/static/277145472012103075527791/

UITableView编辑模式



UITableViewCellEditStyle多功能的实现


实现代码:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        
        
        
    }];
    editAction.backgroundColor = [UIColor blueColor];;
    
    
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Delete"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        
        
    }];
    
    return @[deleteAction,editAction];
}




你可能感兴趣的:(iOS 8 TableviewCell侧滑出现更多Button)