在 Table 视图/集合视图中采用拖放功能在 iPhone 上不起作用
Adopting Drag and Drop in a Table View / Collection View not working on iPhone
有谁知道为什么 在 Table 视图 中采用拖放的 Apple 示例在 iPhone 上不起作用?
重现步骤:
- 从 https://developer.apple.com/documentation/uikit/drag_and_drop/adopting_drag_and_drop_in_a_table_view
下载代码
- 打开项目并将 Deployment target -> Devices 更改为 Universal。
- 运行 iPhone(模拟器)上的应用程序。
- 尝试拖动一些单元格。
拖放功能不起作用,但它的行为方式应与 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)
UITableView
& UICollectionView
有 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()
(我在设置 dragDelegate
和 dropDelegate
之前添加了它,它似乎工作正常)。
有谁知道为什么 在 Table 视图 中采用拖放的 Apple 示例在 iPhone 上不起作用?
重现步骤:
- 从 https://developer.apple.com/documentation/uikit/drag_and_drop/adopting_drag_and_drop_in_a_table_view 下载代码
- 打开项目并将 Deployment target -> Devices 更改为 Universal。
- 运行 iPhone(模拟器)上的应用程序。
- 尝试拖动一些单元格。
拖放功能不起作用,但它的行为方式应与 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)
UITableView
& UICollectionView
有 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()
(我在设置 dragDelegate
和 dropDelegate
之前添加了它,它似乎工作正常)。