TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Daniel Saidi.
LongPressTableViewReordering is a Swift library, that lets you reorder cells in a UITableView by long pressing any cell in the table view.
This project is a Swift adaption of the original obj-c approach posted by Soheil Ahzarpour on raywenderlich.com, March 24, 2014:
I will add more features to this lib if I need more in my own projects, but wherever the project goes, it wouldn’t have existed without Soheil.
To add long press reorder functionality to a table view, make the data source implement the LongPressTableViewReorderer protocol as well. The protocol (due to Swift limitations) must be a bit tweaked to work, but it is fairly straightforward.
First, the protocol requires two backing fields. Just declare them and leave them without an initial value. You will never use the properties yourself, but the protocol extension will use them under the hood.
Second, call the enableLongPressReorderingForTableView(...)
function to enable long press reordering. Since a protocol extension cannot set a target action, you must inject a gesture listener function as use it to call longPressReorderGestureChanged(...)
from your class.
If you know a better way to achieve the same result, feel free to help.
The example project is currently empty. I will add a reorderable table view whenever I manage to find some time in this crazy world of ours.
Versions < 1.0.0 will have breaking changes between minor versions, so LongPressTableViewReordering 0.3.0 may not be compatible with 0.2.0.
Daniel Saidi, [email protected]
LongPressTableViewReordering is available under the MIT license. See the LICENSE file for more info.