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/

相关文章:

iPhone游戏2D阴影

Swift,从数组中连续播放多个动画?

ios - 在一个 UIViewController 中实现对多个 UITableView 的 peek 和 pop

ios - 当我实现 UITableViewRowAction 时,为什么所有节标题行都随表格单元格一起滑动

ios - 在 iOS 中滑动以显示后,试图使表格单元格返回其原始状态

iphone - 圆形矩形按钮后面的黑色衬垫

iphone - 手动核心数据版本控制

ios - 同一个 AVCaptureSession 中的多个 AVCaptureVideoDataOutput

arrays - Swift:为什么创建空白数组时需要空括号?

Swift Quick/Nimble 测试未运行