This repository was archived by the owner on Nov 6, 2018. It is now read-only.
Commit 49152f1 Florian Mielke
committed
1 parent a60308c commit 49152f1 Copy full SHA for 49152f1
File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 7
7
//
8
8
9
9
10
+ #import < QuartzCore/QuartzCore.h>
11
+
12
+
10
13
@class FMMoveTableView;
11
14
12
15
29
32
// Called after the particular row is being dropped to it's new index path
30
33
- (void )moveTableView : (FMMoveTableView *)tableView moveRowFromIndexPath : (NSIndexPath *)fromIndexPath toIndexPath : (NSIndexPath *)toIndexPath ;
31
34
35
+ @optional
36
+
37
+ // Allows to reorder a particular row
38
+ - (BOOL )moveTableView : (FMMoveTableView *)tableView canMoveRowAtIndexPath : (NSIndexPath *)indexPath ;
39
+
32
40
@end
33
41
34
42
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ @implementation FMMoveTableView
119
119
- (void )setup
120
120
{
121
121
UILongPressGestureRecognizer *movingGestureRecognizer = [[UILongPressGestureRecognizer alloc ] initWithTarget: self action: @selector (handleLongPress: )];
122
+ [movingGestureRecognizer setDelegate: self ];
122
123
[self addGestureRecognizer: movingGestureRecognizer];
123
124
[self setMovingGestureRecognizer: movingGestureRecognizer];
124
125
}
@@ -210,6 +211,27 @@ - (NSIndexPath *)adaptedIndexPathForRowAtIndexPath:(NSIndexPath *)indexPath
210
211
#pragma mark -
211
212
#pragma mark Handle long press
212
213
214
+ - (BOOL )gestureRecognizerShouldBegin : (UIGestureRecognizer *)gestureRecognizer
215
+ {
216
+ BOOL shouldBegin = YES ;
217
+
218
+ if ([gestureRecognizer isEqual: [self movingGestureRecognizer ]])
219
+ {
220
+ // Ask the data source if we are allowed to move the touched row
221
+ if ([[self dataSource ] respondsToSelector: @selector (moveTableView:canMoveRowAtIndexPath: )])
222
+ {
223
+ // Grap the touched index path
224
+ CGPoint touchPoint = [gestureRecognizer locationInView: self ];
225
+ NSIndexPath *touchedIndexPath = [self indexPathForRowAtPoint: touchPoint];
226
+
227
+ shouldBegin = [[self dataSource ] moveTableView: self canMoveRowAtIndexPath: touchedIndexPath];
228
+ }
229
+ }
230
+
231
+ return shouldBegin;
232
+ }
233
+
234
+
213
235
- (void )handleLongPress : (UILongPressGestureRecognizer *)gestureRecognizer
214
236
{
215
237
switch ([gestureRecognizer state ])
Original file line number Diff line number Diff line change @@ -113,6 +113,12 @@ - (UITableViewCell *)tableView:(FMMoveTableView *)tableView cellForRowAtIndexPat
113
113
}
114
114
115
115
116
+ - (BOOL )moveTableView : (FMMoveTableView *)tableView canMoveRowAtIndexPath : (NSIndexPath *)indexPath
117
+ {
118
+ return YES ;
119
+ }
120
+
121
+
116
122
- (void )moveTableView : (FMMoveTableView *)tableView moveRowFromIndexPath : (NSIndexPath *)fromIndexPath toIndexPath : (NSIndexPath *)toIndexPath
117
123
{
118
124
NSArray *movie = [[[self movies ] objectAtIndex: [fromIndexPath section ]] objectAtIndex: [fromIndexPath row ]];
You can’t perform that action at this time.
0 commit comments