Fixes for DTGridView #1

Merged
2 commits merged into from Oct 24, 2010
Jump to file or symbol
Failed to load files and symbols.
+28 −4
Split
@@ -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
@@ -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];