Permalink
Browse files

Fixed deselecting products during multi-select, deselecting all selec…

…ts "All"
  • Loading branch information...
1 parent 5c74e59 commit b9f73c321bccf19cd2e161d04e7dcd0430346f62 Kevin Bowes committed Jun 21, 2012
@@ -13,7 +13,7 @@
@interface DashboardViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, ColorPickerViewControllerDelegate> {
- NSArray *selectedProducts;
+ NSMutableArray *selectedProducts;
ASAccount *account;
UITableView *productsTableView;
UIView *topView;
@@ -37,7 +37,7 @@
@property (nonatomic, retain) ASAccount *account;
@property (nonatomic, retain) NSArray *products;
@property (nonatomic, retain) NSArray *visibleProducts;
-@property (nonatomic, retain) NSArray *selectedProducts;
+@property (nonatomic, retain) NSMutableArray *selectedProducts;
@property (nonatomic, retain) UITableView *productsTableView;
@property (nonatomic, retain) UIView *topView;
@property (nonatomic, retain) UIImageView *shadowView;
@@ -356,9 +356,9 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
if (cell.product) {
if (self.selectedProducts) {
- self.selectedProducts = [self.selectedProducts arrayByAddingObject:cell.product];
+ [self.selectedProducts addObject:cell.product];
} else {
- self.selectedProducts = [NSArray arrayWithObject:cell.product];
+ self.selectedProducts = [NSMutableArray arrayWithObject:cell.product];
}
} else {
self.selectedProducts = nil;
@@ -383,10 +383,22 @@ - (void)deselectAllRowsInTableView:(UITableView*)tableView exceptForIndexPath:(N
}
}
+- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
+ Product * p = [self.visibleProducts objectAtIndex:indexPath.row - 1];
+
+ [self.selectedProducts removeObject:p];
+
+ if ([self.selectedProducts count] == 0) {
+ self.selectedProducts = nil;
+ NSIndexPath * ip = [NSIndexPath indexPathForRow:0 inSection:0];
+ [tableView selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionNone];
+ }
+}
+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self deselectAllRowsInTableView:tableView exceptForIndexPath:indexPath];
- self.selectedProducts = (indexPath.row == 0) ? nil : [NSArray arrayWithObject:[self.visibleProducts objectAtIndex:indexPath.row - 1]];
+ self.selectedProducts = (indexPath.row == 0) ? nil : [NSMutableArray arrayWithObject:[self.visibleProducts objectAtIndex:indexPath.row - 1]];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
@@ -179,6 +179,11 @@ - (void)reviewSummaryView:(ReviewSummaryView *)view didSelectRating:(NSInteger)r
}
}
+- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
+ [super tableView:tableView didDeselectRowAtIndexPath:indexPath];
+ [self.reviewSummaryView reloadDataAnimated:YES];
+}
+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
@@ -775,6 +775,11 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
[self.graphView reloadValuesAnimated:YES];
}
+- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
+ [super tableView:tableView didDeselectRowAtIndexPath:indexPath];
+ [self.graphView reloadValuesAnimated:YES];
+}
+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];

0 comments on commit b9f73c3

Please sign in to comment.