iphone - 在 TableView / Collection View 中采用拖放功能在 iPhone 上不起作用

标签 iphone swift uitableview drag-and-drop ios11

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

重现步骤:

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

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

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

没有被调用。

配置:

  • Xcode 版本 9.0 (9A235)
  • Apple Swift 版本 4.0 (swiftlang-900.0.63 clang-900.0.37)
  • 模拟器版本 10.0 (SimulatorApp-829.6 CoreSimulator-494.13.6)

最佳答案

UITableViewUICollectionView 具有 dragInteractionEnabled: 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 设置之前添加了它,它似乎工作正常) .

关于iphone - 在 TableView / Collection View 中采用拖放功能在 iPhone 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46328045/

相关文章:

ios - iPhone 应用程序在设备中崩溃,但它在模拟器中运行

iphone - 禁用iPhone中按钮的点击事件

iOS swift UICollectionView 在滚动超过第一个屏幕后失去单元格约束

ios - 为什么 UITableViewAutomaticDimension 不适用于 sectionFooterHeight?

iphone - 如何在iPhone中使用下拉菜单?

ios - 图像中带有复选框的 UICollectionView Cell

iphone - iOS 上的 libpcap,pcap_next() 总是返回 null

swift - 在swift中将类名作为参数发送

ios - 抓取结果出现在实际抓取之前

ios - 如何让两个不同的表格 View 单元格始终成对显示在同一个表格 View 中?