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];
}




最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容