iOS8之后,UITableViewRowAction实现滑动多个按钮

Posted Kingdev

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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】

以上是关于iOS8之后,UITableViewRowAction实现滑动多个按钮的主要内容,如果未能解决你的问题,请参考以下文章

iOS开发小技巧--iOS8之后的cell自动计算高度

在 pushState 之后 iOS8 Safari :nth-child() 选择器不起作用

ios8 之后的Rate us链接地址----屏幕适配判断 和iOS系统按本判断

iOS 8 之后,还能继续使用 UIActionSheet 和 UIAlertView 吗?

iOS8--改变方向后键盘消失

iOS8:不显示 UIPopoverController 但 iOS7 可以