在 Table 视图/集合视图中采用拖放功能在 iPhone 上不起作用

Adopting Drag and Drop in a Table View / Collection View not working on iPhone

有谁知道为什么 在 Table 视图 中采用拖放的 Apple 示例在 iPhone 上不起作用?

重现步骤:

  1. https://developer.apple.com/documentation/uikit/drag_and_drop/adopting_drag_and_drop_in_a_table_view
  2. 下载代码
  3. 打开项目并将 Deployment target -> Devices 更改为 Universal。
  4. 运行 iPhone(模拟器)上的应用程序。
  5. 尝试拖动一些单元格。

拖放功能不起作用,但它的行为方式应与 iPad 设备上的行为方式相同。连函数

func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem]

未调用。

配置:

UITableView & UICollectionViewdragInteractionEnabled: Bool 个实例属性。

Xcode 的文档:

The default value of this property is true on iPad and false on iPhone. Changing the value to true on iPhone makes it possible to drag content from the table view to another app on iPhone and to receive content from other apps.

TableViewController.swift中添加

tableView.dragInteractionEnabled = true

viewDidLoad()(我在设置 dragDelegatedropDelegate 之前添加了它,它似乎工作正常)。