Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Does anyone know why the Apple example of Adopting Drag and Drop in a Table View is not working on iPhone?

Steps to Reproduce:

  1. Download code from https://developer.apple.com/documentation/uikit/drag_and_drop/adopting_drag_and_drop_in_a_table_view
  2. Open project and change Deployment target -> Devices to Universal.
  3. Run application on iPhone (simulator).
  4. Try to drag some cell.

Drag and drop functionality is not working but it should behave the same way as on the iPad devices. Even the function

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

is not called.

Configuration:

  • Xcode Version 9.0 (9A235)
  • Apple Swift version 4.0 (swiftlang-900.0.63 clang-900.0.37)
  • Simulator Version 10.0 (SimulatorApp-829.6 CoreSimulator-494.13.6)
like image 367
Kaktusiarz Avatar asked Sep 20 '17 17:09

Kaktusiarz


1 Answers

UITableView & UICollectionView have dragInteractionEnabled: Bool instance properties.

Xcode's documentation:

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.

In TableViewController.swift, add

tableView.dragInteractionEnabled = true

into viewDidLoad() (I've added it just before the dragDelegate and dropDelegate are set, and it seems to work fine).

like image 59
caseynolan Avatar answered Nov 15 '22 05:11

caseynolan