zoukankan      html  css  js  c++  java
  • OC,UITableView侧滑删除

    做侧滑的时候发现一个问题,当一个UITableView的cell有的有侧滑,有的没有,当用editActionsForRowAtIndexPath方法的时候发现有点问题,查看了下api,需要用到canEditRowAtIndexPath这个方法

    #import "SkidSidewaysViewController.h"
    
    @interface SkidSidewaysViewController ()<UITableViewDelegate,UITableViewDataSource>
    @property(nonatomic,strong)NSMutableArray *dataArr;
    @property(nonatomic,strong)UITableView *tableView;
    @end
    
    @implementation SkidSidewaysViewController
    #define Identifier @"cell"
    -(NSMutableArray *)dataArr{
        if(!_dataArr){
            _dataArr = [NSMutableArray array];
            for(int i=0;i<20;i++){
                [_dataArr addObject:[NSString stringWithFormat:@"%d",arc4random()%3]];
            }
        }
        return _dataArr;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
        [self.view addSubview:self.tableView];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:Identifier];
    }
    #pragma mark UITableViewDelegate,UITableViewDataSource
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return self.dataArr.count;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier forIndexPath:indexPath];
        cell.textLabel.text = self.dataArr[indexPath.row];
        return cell;
    }
    //判断是否有侧滑
    -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
        if([self.dataArr[indexPath.row] isEqualToString:@"0"]){
            return NO;
        }
        return YES;
    }
    //判断侧滑按钮一共有几个
    - (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
        NSMutableArray *acitonArr = [NSMutableArray array];
        for(int i=0;i<[self.dataArr[indexPath.row] intValue];i++){
            UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%d",i] handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                
            }];
            action.backgroundColor = [UIColor redColor];
            [acitonArr addObject:action];
        }
        
        
        return acitonArr;
    }
    @end
    
  • 相关阅读:
    CSS媒体查询
    重新认识caniuse
    范仁义css3课程---40、box-sizing属性实例
    前端超级实用技巧---2、css、js兼容性查询网站can i use
    日常英语---200221(shrink)
    心得体悟帖---200221(方针:进可攻退可守的方式:先把不熟悉的知识点录)
    心得体悟帖---200221(本来二月份就到了三月之期的)
    心得体悟帖---200220(对不同的人,用不同的处理方式(这个你远远没有理解))
    java中的String.format使用
    android中的ellipsize设置(省略号的问题)
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/10095146.html
Copyright © 2011-2022 走看看