ios-UI

ios11 tableview左滑到底删除禁用

2018-02-27  本文已影响1308人  我的名字就这么长

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){

// delete action

UIContextualAction *deleteAction = [UIContextualAction

contextualActionWithStyle:UIContextualActionStyleDestructive

title:@"删除"

handler:^(UIContextualAction * _Nonnull action,

__kindof UIView * _Nonnull sourceView,

void (^ _Nonnull completionHandler)(BOOL))

{

[tableView setEditing:NO animated:YES];  // 这句很重要,退出编辑模式,隐藏左滑菜单

[self.arr removeObjectAtIndex:indexPath.row];

[_table deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];

[_table reloadData];

completionHandler(true);

}];

UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];

actions.performsFirstActionWithFullSwipe = NO;

return actions;

参考:http://www.cocoachina.com/bbs/read.php?tid-1731241.html

上一篇 下一篇

猜你喜欢

热点阅读