Permalink
Browse files

Added check to ask for permission for a row to be moved

  • Loading branch information...
1 parent a60308c commit 49152f1f873d228567ba910cf3a48b139bf39971 Florian Mielke committed Jul 1, 2012
Showing with 36 additions and 0 deletions.
  1. +8 −0 FMFramework/FMMoveTableView.h
  2. +22 −0 FMFramework/FMMoveTableView.m
  3. +6 −0 FMMoveTable/Classes/FMViewController.m
@@ -7,6 +7,9 @@
//
+#import <QuartzCore/QuartzCore.h>
+
+
@class FMMoveTableView;
@@ -29,6 +32,11 @@
// Called after the particular row is being dropped to it's new index path
- (void)moveTableView:(FMMoveTableView *)tableView moveRowFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath;
+@optional
+
+// Allows to reorder a particular row
+- (BOOL)moveTableView:(FMMoveTableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
+
@end
@@ -119,6 +119,7 @@ @implementation FMMoveTableView
- (void)setup
{
UILongPressGestureRecognizer *movingGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
+ [movingGestureRecognizer setDelegate:self];
[self addGestureRecognizer:movingGestureRecognizer];
[self setMovingGestureRecognizer:movingGestureRecognizer];
}
@@ -210,6 +211,27 @@ - (NSIndexPath *)adaptedIndexPathForRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark -
#pragma mark Handle long press
+- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
+{
+ BOOL shouldBegin = YES;
+
+ if ([gestureRecognizer isEqual:[self movingGestureRecognizer]])
+ {
+ // Ask the data source if we are allowed to move the touched row
+ if ([[self dataSource] respondsToSelector:@selector(moveTableView:canMoveRowAtIndexPath:)])
+ {
+ // Grap the touched index path
+ CGPoint touchPoint = [gestureRecognizer locationInView:self];
+ NSIndexPath *touchedIndexPath = [self indexPathForRowAtPoint:touchPoint];
+
+ shouldBegin = [[self dataSource] moveTableView:self canMoveRowAtIndexPath:touchedIndexPath];
+ }
+ }
+
+ return shouldBegin;
+}
+
+
- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
switch ([gestureRecognizer state])
@@ -113,6 +113,12 @@ - (UITableViewCell *)tableView:(FMMoveTableView *)tableView cellForRowAtIndexPat
}
+- (BOOL)moveTableView:(FMMoveTableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return YES;
+}
+
+
- (void)moveTableView:(FMMoveTableView *)tableView moveRowFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSArray *movie = [[[self movies] objectAtIndex:[fromIndexPath section]] objectAtIndex:[fromIndexPath row]];

0 comments on commit 49152f1

Please sign in to comment.