博客> 关于iOS11之后左滑会自动跳转到某一个UITableViewRowAction方法中的问题
关于iOS11之后左滑会自动跳转到某一个UITableViewRowAction方法中的问题
2018-05-25 03:50 评论:0 阅读:401 tong-tong
ios UItableviewcell编辑 左滑

今天之前我并不知道iOS11有这个"bug",我原来的代码中如下:

  • (NSArray )tableView:(UITableView )tableView editActionsForRowAtIndexPath:(NSIndexPath )indexPath { InvitationListModel model = self.dataArray[indexPath.row]; UITableViewRowAction action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction action, NSIndexPath indexPath) { TYAlertView alertView = [TYAlertView alertViewWithTitle:@"确认结算?" message:nil]; alertView.textFieldHeight = 45; alertView.textFieldFont = kFont(17); [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction action) { NSLog(@"%@",action.title); }]]; [alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction action) { [self deleteAction:model]; }]]; // first way to show TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert]; [self presentViewController:alertController animated:YES completion:nil]; tableView.editing = NO; }]; action0.backgroundColor = [UIColor redColor]; return @[action0]; } 后来加上以下代码:
  • (nullable UISwipeActionsConfiguration )tableView:(UITableView )tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){

    // delete action InvitationListModel model = self.dataArray[indexPath.row]; UIContextualAction deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除" handler:^(UIContextualAction _Nonnull action, __kindof UIView _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { TYAlertView alertView = [TYAlertView alertViewWithTitle:@"确认结算?" message:nil]; alertView.textFieldHeight = 45; alertView.textFieldFont = kFont(17); [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction action) { NSLog(@"%@",action.title); }]]; [alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction action) { [self deleteAction:model]; }]]; // first way to show TYAlertController alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert]; [self presentViewController:alertController animated:YES completion:nil]; [tableView setEditing:NO animated:YES]; // 这句很重要,退出编辑模式,隐藏左滑菜单 completionHandler(true); }]; deleteAction.backgroundColor = [UIColor redColor]; UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]]; actions.performsFirstActionWithFullSwipe = NO; return actions; } 完美解决

收藏
0
sina weixin mail 回到顶部