This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAB_DragableTable.h
66 lines (48 loc) · 2.66 KB
/
AB_DragableTable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// AB_Dragable.h
// WorkingCopy
//
// Created by Anders Borum on 04/08/16.
// Copyright © 2016 Applied Phasor. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
// UIViewController should implement this protocol to supporting dragging.
// It does not have to be a UITableViewController but it needs a UITableView.
@protocol AB_DragableContainerDelegate
// Table view where cells can be dragged from
-(UITableView*)dragableContainerView;
// quick check if can be entered
-(BOOL)isDragCellRelevant:(UITableViewCell*)cell;
// To avoid having duplicates in the stack of view controllers, we
// must be able to check if cell will end up as some specific target.
// This should not have expensive code.
-(BOOL)isCell:(UITableViewCell*)cell equivalentToTarget:(UIViewController<AB_DragableContainerDelegate>*)target;
// Creates and initializes view-controller representing the content of the given cell.
// Used when dragging cells deeper into the table hierarchy.
// New instances of view-controllers are needed, even though you have existing at hand.
// Method is called on the view controller containing cell.
-(UIViewController<AB_DragableContainerDelegate>*)dragTargetViewControllerFromCell:(UITableViewCell*)cell;
// Creates and initializes view-controller representing existing view controller.
// Used when dragging cells out if the hierarchy through the back button.
// New instances of view-controllers are needed, even though you have existing at hand.
-(UIViewController<AB_DragableContainerDelegate>*)dragTargetViewController:(UIViewController<AB_DragableContainerDelegate>*)vc;
// title in navigation bar, when this view-controller is the current one.
-(NSString*)dragTitle;
// Perform result of drag operation. Even if something is wrong the done-block must be called
// or the drag state is never left. Method is called on the view controller where dragging started.
-(void)completeDragOfCell:(UITableViewCell*)cell
toTarget:(UIViewController<AB_DragableContainerDelegate>*)viewController
done:(void (^ _Nonnull)(void))block;
@optional
// default is to find assume all view controllers implementing AB_DragableContainerDelegate protocol are relevant
-(BOOL)isViewControllerRelevant:(UIViewController<AB_DragableContainerDelegate>*)viewController;
// if not implemented dragging is always allowed
-(BOOL)draggingAllowed;
@end
@interface UITableViewCell (AB_DragableTable)
// You need to call this on all cells that are dragable, but it is safe to register multiple times.
// Often called in tableView:cellForRowAtIndexPath: or tableView:willDisplayCell:forRowAtIndexPath:
-(void)registerForDragging;
@end
NS_ASSUME_NONNULL_END