Easy UITableView drag-and-drop cell reordering

Overview

SwiftReorder

NOTE: Some users have encountered compatibility issues when using this library with recent versions of iOS. For apps targeting iOS 11 and up, it's recommended to use the built-in UITableView drag and drop API instead.

SwiftReorder is a UITableView extension that lets you add long-press drag-and-drop reordering to any table view. It's robust, lightweight, and fully customizable.

Demo

Features

  • Smooth animations
  • Automatic edge scrolling
  • Works with multiple table sections
  • Customizable shadow, scaling, and transparency effects

Installation

CocoaPods

To integrate SwiftReorder into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftReorder', '~> 7.2'

Carthage

To integrate SwiftReorder into your Xcode project using Carthage, specify it in your Cartfile:

github "adamshin/SwiftReorder" ~> 7.2

Remember to add SwiftReorder to your Carthage build phase:

$(SRCROOT)/Carthage/Build/iOS/SwiftReorder.framework

and

$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftReorder.framework

Manually

You can integrate SwiftReorder into your project manually by copying the contents of the Source folder into your project.

Usage

Setup

  • Add the following line to your table view setup.
override func viewDidLoad() {
    // ...
    tableView.reorder.delegate = self
}
  • Add this code to the beginning of your tableView(_:cellForRowAt:).
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let spacer = tableView.reorder.spacerCell(for: indexPath) {
        return spacer
    }
    // ...
}
  • Implement the tableView(_:reorderRowAt:to:) delegate method, and others as necessary.
extension MyViewController: TableViewReorderDelegate {
    func tableView(_ tableView: UITableView, reorderRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        // Update data model
    }
}

This method is analogous to the UITableViewDataSource method tableView(_:moveRowAt:to:). However, it may be called multiple times in the course of one drag-and-drop action.

Customization

SwiftReorder exposes several properties for adjusting the style of the reordering effect. For example, you can add a scaling effect to the selected cell:

tableView.reorder.cellScale = 1.05

Or adjust the shadow:

tableView.reorder.shadowOpacity = 0.5
tableView.reorder.shadowRadius = 20
Comments
  • Dragging a cell to the top makes the tableview shake

    Dragging a cell to the top makes the tableview shake

    I have implemented the SwiftReorder and it's really cool. I'm facing an issue when I drag a cell from the bottom to up, but when the cell gets to the top, the whole tableview starts to shake as you can see in the video attached. is there a way to fix it?

    Sample.zip

    opened by dyegos 10
  • Support of Swift Package Manager

    Support of Swift Package Manager

    Adds Package.swift file which enables usage with SPM and closes #60. Note, that the most correct usage with SPM will be possible only when there is new release that includes Package.swift. Until then, dependency can be added by branch or commit hash which is not allowed in published packages.

    opened by TwoDollarsEsq 9
  • Are there any options to disable Automatic edge scrolling?

    Are there any options to disable Automatic edge scrolling?

    I got this issue https://www.youtube.com/watch?v=5vmFZPdEqO0 . Since this issue has not fixed yet. I was just wondering if there are any options to disable Automatic edge scrolling?

    opened by tungdx 9
  • add initialSourceIndexPath and finalDestinationIndexPath

    add initialSourceIndexPath and finalDestinationIndexPath

    When I intent to send a urlRequest that inform back-end the changes of model, I found that I can only do this in tableview(_:reorderRowAt:to). However this means that during the Drag&Drop I have to send lots of urlRequest which is not necessary. So I added two properties to help. Usage:

    func tableViewDidFinishReordering(_ tableView: UITableView) { guard let rowS = tableView.reorder.initialSourceIndexPath?.row, let rowD = tableView.reorder.finalDestinationIndexPath?.row else { return } print("move (rowS) to (rowD)") }

    (This is my first pull request. Hope you don't mind if I make some mistakes. )

    opened by RickeyBoy 6
  • Add TableViewReorderDelegate tableView(_:targetIndexPathForMoveFromRowAt:to)

    Add TableViewReorderDelegate tableView(_:targetIndexPathForMoveFromRowAt:to)

    This TableViewReorderDelegate method optionally gives the reorder delegate an opportunity to selectively allow or modify reordering between sections or groups of rows. This is equivalent to the UITableViewDelegate method tableView(targetIndexPathForMoveFromRowAt:toProposedIndexPath:). Let me know if a sample project demonstrating this capability would be helpful, or if this functionality is already possible using the existing codebase.

    opened by larrylegend 5
  • Question: Pinch detection

    Question: Pinch detection

    Hey there!

    Sorry to take your issue tracker hostage but I couldn't really find an answer to my question. I am currently trying to replicate Procreate's "pinch to merge layers" ListView that you can see in this short YouTube video. I thought I found a solution with your library but after taking a closer look I think it's actually not possible as of now.

    I am really new to iOS app creation and was wondering if you could give me some hints on how to implement the above. I think your code is a good starting point. I know for a fact that it is possible to drag and drop multiple ListItems as I found that on the Apple API page somewhere. Maybe it has been done that way, where the pinch triggers somehow the drag and drop action and while you still hold the pinched items your code would somehow kick it, allowing reordering.

    I am actually only interested in the pinching part as the ListView that I have in my project does not need reordering.

    Sorry for bothering you and any inconveniences I cause :)

    Edit: I am coming from Android and apparently ListView is called UITableView over here :)

    opened by mainrs 4
  • Picking up a cell breaks all other cells

    Picking up a cell breaks all other cells

    I have cells with custom properties, but when I pick up any cell, the rest of them seem to reset and behave unexpectedly. Here is an example of my issue:

    https://gfycat.com/bleakconcernedarmadillo

    This seems to be a bug unique to this pod, as other ones I have tried do not replicate this issue. Let me know if there's anything you want me to provide to figure this out.

    opened by MohamedElgharbawy 4
  • Multi-Section TableView reordering

    Multi-Section TableView reordering

    I have a tableview with multiple sections and each section has 1 row. When I try reordering it crashes saying that attempt to insert row 1 into section 1, but there are only 1 rows in section 1 after the update I guess it's because the tableView tries to add tile to the destination section but I return 1 on numberOfRowsInSection. Is there any solution to solve this issue? Thanks in advance

    opened by danlaunch 4
  • Is it possible to change the Image when begin reordering the cell

    Is it possible to change the Image when begin reordering the cell

    i am going to display an image, for example a black color of star image, when i trying to reordering the cell, the star will change to yellow color. After finish the reordering, the yellow star will change to black star.

    opened by Iamivan1996 4
  • Section header bug

    Section header bug

    I have a custom section header cell using override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?. Some of the sections have no cells in them. When I attempt to drag a cell to an empty section the section header will be a white blank rectangle.

    This happens when hovering over an empty section while dragging and persists after a cell is dropped into the empty section. Sometimes it will fix itself after I touch and hold the cell that dropped into the empty section so I can drag it and then drop it immediately without moving it anywhere.

    EDIT: I managed to work around this bug by creating the section header programatically instead of with the storyboard editor.

    opened by diddledot 4
  • Feature Request: Vibration when dragging cell moves (like current apple feature)

    Feature Request: Vibration when dragging cell moves (like current apple feature)

    Hey there!

    I also allow drag and drop via apple's functionality in edit mode, and am trying to make it match.

    One big thing that is different that I think is really cool is that with apple's edit functionality, you feel a slight vibration when your drag moves over a tableviewcell.

    Also - awesome library, clean code. If you want to give me a pointer on where the code detects the cell moving over another cell & re-adjusting I might give this a shot. I'd have to do some research on how to programmatically give that vibration.

    opened by thejeff77 3
  • two tableview problem

    two tableview problem

    Hi,

    I have two tableviews in the vc. I can move from row 1 to row 0 in my first tableview but if I want to move from row 1 to row 0 in my second tableview, it doesn't work.

    Can u help me about this problem?

    opened by koust 6
  • Reordering to top is broken on iOS 13.3, Xcode 11.3.1

    Reordering to top is broken on iOS 13.3, Xcode 11.3.1

    So spend half a day today trying to figure out and maybe fix a bug with cell reordering when you try to reorder a cell to the top with a scrolling involved. Basically all you need to do is to scroll at least a little bit down and then try to reorder cell to the very top. There'll be an animation glitch on the last cell reordering. It especially obvious for grouped table views. I used iPhone SE for tests.

    1

    I tried to force layout first and contentOffset restore after to prevent jumps but while I almost fixed a jump glitch cells content and sizes started to glitch so no idea how to fix this one.

    opened by anton-plebanovich 12
  • Fix/reload data animation glitch fix

    Fix/reload data animation glitch fix

    Fixes https://github.com/adamshin/SwiftReorder/issues/6

    Fixed animation glitch when try to reload rows in a long list with dynamic cells. You can check a bug here - https://github.com/anton-plebanovich/SwiftReorder/tree/f7afafd9a5518d6b8c06b69f119ef1a64e4a66db And a fix here - https://github.com/anton-plebanovich/SwiftReorder/tree/9b2744abbd8817769f8fa9335f4e0949f88b91f8

    opened by anton-plebanovich 1
  • A way to disable/enable reordering on a tableviewCell.

    A way to disable/enable reordering on a tableviewCell.

    Can you please guide me how can i disable scrolling for specific table view cell. I want to enable/disable specific cells in tableview. Please let me know, is there any way to do that? I will be very thankful to you.

    opened by RabiaAwan 2
Owner
Adam Shin
Code wrangler
Adam Shin
A UITableView extension that enables cell insertion from the bottom of a table view.

ReverseExtension UITableView extension that enabled to insert cell from bottom of tableView. Concept It is difficult to fill a tableview content from

Taiki Suzuki 1.7k Dec 15, 2022
Objective-C library for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers.

ios-dragable-table-cells Support for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers. You drag cells by tapping and hold

Anders Borum 49 Aug 23, 2022
HoverConversion realized vertical paging with UITableView. UIViewController will be paged when reaching top or bottom of UITableView contentOffset.

HoverConversion ManiacDev.com referred. https://maniacdev.com/2016/09/hoverconversion-a-swift-ui-component-for-navigating-between-multiple-table-views

Taiki Suzuki 166 Feb 1, 2022
a TableView have thumbnail cell only, and you can use gesture let it expands other expansionView, all diy

ZYThumbnailTableView #####可展开型预览TableView,开放接口,完全自由定制 #####An expandable preview TableView, custom-made all the modules completely with open API you c

null 950 Oct 17, 2022
A PageView, which supporting scrolling to transition between a UIView and a UITableView

YXTPageView ##A Page View, which support scrolling to transition between a UIView and a UITableView UIView (at the top) UITableView (at the bottom) In

Hanton Yang 68 May 25, 2022
Simple and beautiful stacked UIView to use as a replacement for an UITableView, UIImageView or as a menu

VBPiledView simple but highly effective animation and interactivity! By v-braun - viktor-braun.de. Preview Description Very simple and beautiful stack

Viktor Braun 168 Jan 3, 2023
Protocol-oriented UITableView management, powered by generics and associated types.

DTTableViewManager Features Powerful mapping system between data models and cells, headers and footers Automatic datasource and interface synchronizat

Denys Telezhkin 454 Nov 9, 2022
INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application

INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application. MultilevelTableView is a simple component, which lets you use the tableview with multilevel tree view in your project.

INTUZ 3 Oct 3, 2022
A declarative api for working with UITableView.

⚡️ Lightning Table Lightning Table provides a powerful declarative API for working with UITableView's. Table views are the foundation of almost every

Electric Kangaroo 28 Aug 25, 2021
A simple way to create a UITableView for settings in Swift.

QuickTableViewController A simple way to create a table view for settings, including: Table view cells with UISwitch Table view cells with center alig

Cheng-Yao Lin 525 Dec 20, 2022
A pixel perfect replacement for UITableView section index, written in Swift

MYTableViewIndex MYTableViewIndex is a re-implementation of UITableView section index. This control is usually seen in apps displaying contacts, track

Yury 520 Oct 27, 2022
A subclass of UITableView that styles it like Settings.app on iPad

TORoundedTableView As of iOS 13, Apple has released an official version of this table view style called UITableViewStyleInsetGrouped! Yay! In order to

Tim Oliver 162 Nov 2, 2022
A simpler way to do cool UITableView animations! (╯°□°)╯︵ ┻━┻

TableFlip (╯°□°)╯︵ ┻━┻ ┬──┬ ノ( ゜-゜ノ) Animations are cool. UITableView isn't. So why not make animating UITableView cool? The entire API for TableFlip

Joe Fabisevich 555 Dec 9, 2022
Simple single-selection or multiple-selection checklist, based on UITableView

SelectionList Simple single-selection or multiple-selection checklist, based on UITableView. Usage let selectionList = SelectionList() selectionList.i

Yonat Sharon 111 Oct 6, 2022
A declarative wrapper approach to UITableView

Thunder Table Thunder Table is a useful framework which enables quick and easy creation of table views in iOS, making the process of creating complex

3 SIDED CUBE 20 Aug 25, 2022
Elegant and easy way to integrate pagination with dummy views

AZTableView Controller Features Automatic pagination handling No more awkward empty TableView screen AZ TableView controller give you advantage to con

Afroz Zaheer 73 Oct 17, 2022
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.

MGSwipeTableCell MGSwipeTableCell is an easy to use UITableViewCell subclass that allows to display swipeable buttons with a variety of transitions. T

Imanol Fernandez 7k Dec 26, 2022
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

Christopher Wendel 7.2k Dec 31, 2022