ListView: Reordering Cells

TKListView supports reordering cells. When reordering is enabled a drag handle appears in each cell. Using this handle cells can be dragged thus changing the order of items.

Enable cell reorder

Use the allowsCellReorder property to enable user to reorder cells. When reordering is allowed cells will display a draggable reorder handle as a visual hint.

_listView.allowsCellReorder = YES;
self.listView.allowsCellReorder = true
this.listView.AllowsCellReorder = true;

Responding to cell reorder interaction

After the user performs a reorder gesture the following delegate method from the TKListViewDelegate protocol will be called - listView:didReorderItemFromIndexPath:toIndexPath:

This is the place where you get information about which item was reordered and from what position and to what position. There you need to reorder your source data.

- (void)listView:(TKListView *)listView didReorderItemFromIndexPath:(NSIndexPath *)originalIndexPath toIndexPath:(NSIndexPath *)targetIndexPath
    TKListViewCell *cell = [listView cellForItemAtIndexPath:originalIndexPath];
    cell.backgroundView.backgroundColor = [UIColor whiteColor];
    [_dataSource listView:listView didReorderItemFromIndexPath:originalIndexPath toIndexPath:targetIndexPath];
func listView(_ listView: TKListView, didReorderItemFrom originalIndexPath: IndexPath, to targetIndexPath: IndexPath) {
    let cell = listView.cellForItem(at: originalIndexPath)
    cell!.backgroundView?.backgroundColor = UIColor.white
    self.dataSource .listView(listView, didReorderItemFrom: originalIndexPath, to: targetIndexPath)
public override void DidReorderItemFromIndexPath (TKListView listView, NSIndexPath originalIndexPath, NSIndexPath targetIndexPath)
    TKListViewCell cell = listView.CellForItem(originalIndexPath);
    cell.BackgroundView.BackgroundColor = UIColor.White;
    this.owner.dataSource.DidReorderItemFromTo (listView, originalIndexPath, targetIndexPath);

*In case you are using TKDataSource you may set it as a delegate for TKListView. With such a setup you will not need to reorder your data manually. TKDataSource will handle that for you.

_listView.dataSource = _dataSource;
_dataSource.allowItemsReorder = YES;
self.listView.dataSource = self.dataSource
self.dataSource.allowItemsReorder = true
this.listView.WeakDataSource = this.dataSource;
this.dataSource.AllowItemsReorder = true;