Skip to content

Commit

Permalink
ensure selection is also updated for non-visible cells
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Nov 21, 2012
1 parent 73d50e8 commit bbfa8be
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions PSTCollectionView/PSTCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ - (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseId
return view;
}


- (NSArray *)allCells {
return [[_allVisibleViewsDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return [evaluatedObject isKindOfClass:[PSTCollectionViewCell class]];
}]];
}

- (NSArray *)visibleCells {
return [[_allVisibleViewsDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return [evaluatedObject isKindOfClass:[PSTCollectionViewCell class]] && CGRectIntersectsRect(self.bounds, [evaluatedObject frame]);
Expand Down Expand Up @@ -530,7 +537,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if (!self.allowsMultipleSelection) {
// temporally unhighlight background on touchesBegan (keeps selected by _indexPathsForSelectedItems)
for (PSTCollectionViewCell* visibleCell in self.visibleCells) {
for (PSTCollectionViewCell* visibleCell in [self allCells]) {
visibleCell.highlighted = NO;
visibleCell.selected = NO;

Expand Down Expand Up @@ -586,7 +593,7 @@ - (void)cellTouchCancelled {
// TODO: improve behavior on touchesCancelled
if (!self.allowsMultipleSelection) {
// highlight selected-background again
for (PSTCollectionViewCell* visibleCell in self.visibleCells) {
for (PSTCollectionViewCell* visibleCell in [self allCells]) {
NSIndexPath* indexPathForVisibleItem = [self indexPathForCell:visibleCell];
visibleCell.selected = [_indexPathsForSelectedItems containsObject:indexPathForVisibleItem];
}
Expand Down

0 comments on commit bbfa8be

Please sign in to comment.