zoukankan      html  css  js  c++  java
  • iOS8之后,UITableViewRowAction实现滑动多个按钮

    #pragma mark - View lifeCycle
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor whiteColor];
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
    }
    
    #pragma mark - UITableViewDataSource Methods
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.dataArray.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        cell.textLabel.text = self.dataArray[indexPath.row];
        return cell;
    }
    
    #pragma mark - UITableViewDelegate Methods
    
    - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
            NSLog(@"删除-%@", @(indexPath.row));
            [self.dataArray removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }];
        
        UITableViewRowAction *otherAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
            NSLog(@"置顶-%@", @(indexPath.row));
            [self.dataArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
            NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
            [self.tableView moveRowAtIndexPath:indexPath toIndexPath:toIndexPath];
        }];
        
        return @[deleteAction, otherAction];
    }
    
    
    #pragma mark - getter Methods
    
    - (NSMutableArray *)dataArray {
        if (!_dataArray) {
            _dataArray = [NSMutableArray array];
            [_dataArray addObjectsFromArray:@[@"Kingdev:row:0",
                                              @"Kingdev:row:1",
                                              @"Kingdev:row:2",
                                              @"Kingdev:row:3",
                                              @"Kingdev:row:4",
                                              @"Kingdev:row:5",
                                              @"Kingdev:row:6",
                                              @"Kingdev:row:7",
                                              @"Kingdev:row:8",
                                              @"Kingdev:row:9",
                                              @"Kingdev:row:10",
                                              @"Kingdev:row:11",
                                              @"Kingdev:row:12"
                                              ]];
        }
        return _dataArray;
    }
    尊重作者劳动成果,转载请注明: 【kingdev】
  • 相关阅读:
    python中自定义模块导入
    EditText------Android
    Fragment类实现
    Android文件访问
    python中pip使用国内镜像提高安装速度
    esri/geometry包 (arcgis api for js)
    【CSDN 编辑器 MarkDowm 使用技巧】
    for 循环 :从指定下标开始,并指定步长
    【车牌识别】-车牌中字符分割代码详解
    【 Linux 常用命令】
  • 原文地址:https://www.cnblogs.com/xiu619544553/p/5606156.html
Copyright © 2011-2022 走看看