【问题标题】:iOS11 Drag behavior not working in UITableViewiOS11拖动行为在UITableView中不起作用
【发布时间】:2018-07-03 07:58:17
【问题描述】:

我在开发 Drag&Drop iOS11 功能以允许在应用程序之间发送和接收数据时遇到问题。

在视图控制器的 tableView 中,dragDelegatedropDelegateviewDidLoad 上分配给视图控制器本身,我实现了

- (NSArray<UIDragItem *> *)tableView:(UITableView *)tableView itemsForBeginningDragSession:(id<UIDragSession>)session atIndexPath:(NSIndexPath *)indexPath 方法,但它永远不会被调用。

放置行为正常工作,并且表格视图可以使用来自其他应用程序(例如照片或便笺)的项目。但是当我点击一个表格视图行几秒钟时,什么也没有发生。提升动画不会出现,拖动代理也不会触发。

有什么想法吗?我错过了什么吗?

【问题讨论】:

    标签: ios uitableview drag-and-drop ios11


    【解决方案1】:

    在 iPhone 上,除了设置 dragDelegate 之外,您还必须将 UITableView 上的 dragInteractionEnabled 设置为 true。在 iPad 上,此属性默认设置为 true。

    【讨论】:

      【解决方案2】:

      请尝试以下委托方法来重新排序单元格。

      - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
      {
      return UITableViewCellEditingStyleNone;
      }
      

      在您的项目中实现以下 UITableView 数据源方法。

       - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
      return YES;
      }
      
      - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
      {
      [dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
      [self.tableView reloadData];
      }
      

      【讨论】:

      • 什么都不会抛出 itemsForBeginningDragSession 委托方法......谢谢Pankaj
      猜你喜欢
      • 2013-10-06
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      相关资源
      最近更新 更多