iOS8 之后tableview的delegate中新增加的代理方法,可以在滑动的时候添加多个按钮。

iOS8 之后tableview的delegate中新增加的代理方法,可以在滑动的时候添加多个按钮。

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self.array removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
}];

// deleteAction.backgroundColor = [UIColor greenColor]; //设置按钮颜色
UITableViewRowAction *ddAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"添加" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"点击了添加");
}];


return @[deleteAction,ddAction];

}

 

posted on 2016-06-03 12:46  我就是一种相逢  阅读(200)  评论(0编辑  收藏  举报

导航