Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes for DTGridView #1

Merged
2 commits merged into from

2 participants

@aufflick

Hi Daniel,

As promised, some fixes. Hopefully the commit comments make sense. They may not be the nicest way to fix the problems, so feel free to rework as desired.

Mark.

aufflick added some commits
@aufflick aufflick I found a bug in DTGridView where changes to the underlying data
don't become visible when you pop back to a DTGridView from a
subsequent navigation controller view.

What actually happens is that the changes are noticed -
addCellWithInfo is called for each cell, but the previous views are
not removed. So if I pop back and forth (making changes to the
underlying data each time) I see the subviews count continually
increase. Since the view is underneath the other views it is not
visible.

Adding a call to removeCellWithInfo for each addCell didn't work
because it seems that some entries in gridCells have lightweight info
objects even if the cell is visible on screen.

The fix to addCellWithInfo feels a little hacky, but given the small number of subviews
onscreen at any one time it will at least be fast.
0ccf34c
@aufflick aufflick variable initialisation to keep clang happy/quiet 991343a
@danielctull
Owner

Cheers for doing this Mark, hope it wasn't too much hassle. I'm going to pull this in over the weekend. It's also reminded me of another issue with unintentionally removing the scroll bars, because the scroll bars are a subview of the UIScrollView.

@aufflick

You know, I never noticed that, but you're right! I look forward to the fix ;)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2010
  1. @aufflick

    I found a bug in DTGridView where changes to the underlying data

    aufflick authored
    don't become visible when you pop back to a DTGridView from a
    subsequent navigation controller view.
    
    What actually happens is that the changes are noticed -
    addCellWithInfo is called for each cell, but the previous views are
    not removed. So if I pop back and forth (making changes to the
    underlying data each time) I see the subviews count continually
    increase. Since the view is underneath the other views it is not
    visible.
    
    Adding a call to removeCellWithInfo for each addCell didn't work
    because it seems that some entries in gridCells have lightweight info
    objects even if the cell is visible on screen.
    
    The fix to addCellWithInfo feels a little hacky, but given the small number of subviews
    onscreen at any one time it will at least be fast.
  2. @aufflick
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 4 deletions.
  1. +1 −1  DTGridView.xcodeproj/project.pbxproj
  2. +27 −3 DTGridView/DTGridView.m
View
2  DTGridView.xcodeproj/project.pbxproj
@@ -319,7 +319,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
- SDKROOT = iphoneos;
+ SDKROOT = iphoneos3.2;
};
name = Debug;
};
View
30 DTGridView/DTGridView.m
@@ -200,6 +200,18 @@ - (void)addCellWithInfo:(NSObject<DTGridViewCellInfoProtocol> *)info {
[[gridCells objectAtIndex:info.yPosition] replaceObjectAtIndex:info.xPosition withObject:cell];
[self insertSubview:cell atIndex:0];
+
+ // remove any existing view at this frame
+ for (UIView *v in self.subviews) {
+ if (v.frame.origin.x == cell.frame.origin.x &&
+ v.frame.origin.y == cell.frame.origin.y &&
+ v != cell)
+ {
+ [v removeFromSuperview];
+ break;
+ }
+ }
+
[cell release];
}
@@ -286,8 +298,8 @@ - (void)loadData {
NSMutableArray *cellInfoArrayRows = [[NSMutableArray alloc] init];
- CGFloat maxHeight;
- CGFloat maxWidth;
+ CGFloat maxHeight = 0;
+ CGFloat maxWidth = 0;
for (NSInteger i = 0; i < self.numberOfRows; i++) {
@@ -356,6 +368,18 @@ - (void)loadData {
self.gridCells = cellInfoArrayRows;
[cellInfoArrayRows release];
+ if ([self.subviews count] > [self.gridCells count]) {
+ // the underlying data must have reduced, time to iterate
+ NSSet *gridCellsSet = [NSSet setWithArray:self.gridCells];
+ NSArray *subviewsCopy = [self.subviews copy];
+
+ for (DTGridViewCell *cell in subviewsCopy) {
+ if (![gridCellsSet member:cell])
+ [cell removeFromSuperview];
+ }
+
+ [subviewsCopy release];
+ }
}
- (void)checkViews {
@@ -574,7 +598,7 @@ - (DTGridViewCell *)cellForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex
- (void)scrollViewToRow:(NSInteger)rowIndex column:(NSInteger)columnIndex scrollPosition:(DTGridViewScrollPosition)position animated:(BOOL)animated {
- CGFloat xPos, yPos;
+ CGFloat xPos = 0, yPos = 0;
CGRect cellFrame = [[[self.gridCells objectAtIndex:rowIndex] objectAtIndex:columnIndex] frame];
Something went wrong with that request. Please try again.