【问题标题】:Adopting Drag and Drop in a Table View / Collection View not working on iPhone在表视图/集合视图中采用拖放在 iPhone 上不起作用
【发布时间】:2018-03-01 20:50:37
【问题描述】:

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

复制步骤:

  1. https://developer.apple.com/documentation/uikit/drag_and_drop/adopting_drag_and_drop_in_a_table_view下载代码
  2. 打开项目并更改部署目标 -> 设备为通用。
  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)

【问题讨论】:

    标签: iphone swift uitableview drag-and-drop ios11


    【解决方案1】:

    UITableView & UICollectionView 具有 dragInteractionEnabled: Bool 实例属性。

    Xcode 的文档:

    此属性的默认值在 iPad 上为 true,在 iPhone 上为 false。在 iPhone 上将值更改为 true 可以将内容从 table view 拖动到 iPhone 上的另一个应用程序并接收来自其他应用程序的内容。

    TableViewController.swift中,添加

    tableView.dragInteractionEnabled = true

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

    【讨论】:

    • 感谢您的解决方案。我打算只在同一个应用程序的表格视图中拖动项目,这样文档就不清楚了。
    • 工作,谢谢,你知道如何将该单元格拖动到选项卡视图的另一个选项卡吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多