fix crasher (somehow, might be glitchy)
authorkoda
Wed, 08 Dec 2010 17:48:33 +0100 (2010-12-08)
changeset 4486 2c8e4d859d37
parent 4485 85695e3d2623
child 4488 e83216eba1db
fix crasher (somehow, might be glitchy)
project_files/HedgewarsMobile/Classes/HoldTableViewCell.h
project_files/HedgewarsMobile/Classes/HoldTableViewCell.m
project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
--- a/project_files/HedgewarsMobile/Classes/HoldTableViewCell.h	Wed Dec 08 15:18:08 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/HoldTableViewCell.h	Wed Dec 08 17:48:33 2010 +0100
@@ -29,6 +29,7 @@
 
 @interface HoldTableViewCell : UITableViewCell {
     id<HoldTableViewCellDelegate> delegate;
+    NSTimeInterval time;
 }
 
 @property (nonatomic,assign) id<HoldTableViewCellDelegate> delegate;
--- a/project_files/HedgewarsMobile/Classes/HoldTableViewCell.m	Wed Dec 08 15:18:08 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/HoldTableViewCell.m	Wed Dec 08 17:48:33 2010 +0100
@@ -18,8 +18,6 @@
  * File created on 03/07/2010.
  */
 
-//http://devblog.wm-innovations.com/2010/03/30/custom-swipe-uitableviewcell/
-
 
 #import "HoldTableViewCell.h"
 #import "CGPointUtils.h"
@@ -38,17 +36,25 @@
 }
 
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
-    [self performSelector:@selector(holdAction) withObject:nil afterDelay:0.4];
+    UITouch *touch = [[event allTouches] anyObject];
+    
+    time = touch.timestamp; 
+    [self performSelector:@selector(holdAction) withObject:nil afterDelay:0.25];
 
     [super touchesBegan:touches withEvent:event];
 }
 
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
-    [NSObject cancelPreviousPerformRequestsWithTarget:self
-                                             selector:@selector(holdAction)
-                                               object:nil];
-
-    [super touchesEnded:touches withEvent:event];
+    UITouch *touch = [[event allTouches] anyObject];
+    
+    if ( touch.timestamp - time < 0.25 ) {
+        [NSObject cancelPreviousPerformRequestsWithTarget:self
+                                                 selector:@selector(holdAction)
+                                                   object:nil];
+        
+        [super touchesEnded:touches withEvent:event];
+    } else
+        [super touchesCancelled:touches withEvent:event];
 }
 
 -(void) holdAction {
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Wed Dec 08 15:18:08 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Wed Dec 08 17:48:33 2010 +0100
@@ -253,19 +253,7 @@
     NSInteger row = [indexPath row];
     NSInteger section = [indexPath section];
 
-    if (section == 0) {
-        NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:[indexPath row]];
-        UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
-        SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView;
-
-        NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1;
-        NSNumber *newNumber = [NSNumber numberWithInt:[self filterNumberOfHogs:increaseNumber]];
-        [squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal];
-        [selectedRow setObject:newNumber forKey:@"number"];
-
-        cell.imageView.image = [self drawHogsRepeated:[newNumber intValue]];
-        [cell setNeedsLayout];
-    } else {
+    if (section == 1 && [self.listOfTeams count] > row) {
         [self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]];
         [self.listOfTeams removeObjectAtIndex:row];
 
@@ -277,6 +265,18 @@
         [aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
         [aTableView endUpdates];
     }
+    if (section == 0 && [self.listOfSelectedTeams count] > row) {
+        NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:row];
+        UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
+        SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView;
+
+        NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1;
+        NSNumber *newNumber = [NSNumber numberWithInt:[self filterNumberOfHogs:increaseNumber]];
+        [squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal];
+        [selectedRow setObject:newNumber forKey:@"number"];
+
+        cell.imageView.image = [self drawHogsRepeated:[newNumber intValue]];
+    }
 }
 
 -(void) holdAction:(NSString *)content {