美文网首页
UITableVIewCell 侧滑显示多个按钮

UITableVIewCell 侧滑显示多个按钮

作者: 树根曰 | 来源:发表于2017-01-03 17:37 被阅读0次
681933-20150926014401615-1890813765.jpg
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                                                                         title:@"删除"
                                                                       handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                                                                           NSLog(@"删除");
                                                                       }];
    UITableViewRowAction *rowActionSec = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                                                                            title:@"标记"
                                                                          handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                                                                              NSLog(@"标记");
                                                                          }];
    rowActionSec.backgroundColor = [UIColor greenColor];
    NSArray *arr = @[rowAction,rowActionSec];
    return arr;
}

block里面是点击方法 , 这个委托是ios8之后的才有,如果项目只适配ios8以上就可以不用自己写按钮了。返回值是 UITableViewRowAction 的数组
UITableViewRowAction 的大小自动根据文字适配

相关文章

网友评论

      本文标题:UITableVIewCell 侧滑显示多个按钮

      本文链接:https://www.haomeiwen.com/subject/ngjnvttx.html