• 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】
  • 相关阅读:
    java zxing生成二维码
    忘记MySQL root密码重置MySQL root密码
    Java通过ScriptEngine 执行js脚本案例
    两个自定义对象List列表取交集(intersection)
    Java 判断Windows下某个进程是否运行
    Layer文件上传操作
    Jmeter AbstractJavaSamplerClient 案例
    Jaspersoft Studio 导出PDF格式中文不显示
    使用gradle的application插件进行Spring-boot项目打包
    jQuery Ajax应用总结
  • 原文地址:https://www.cnblogs.com/xiu619544553/p/5606156.html
Copyright © 2020-2023  润新知