DTGridView
DTGridView copied to clipboard
Invalid array access when changing grid orientation
Invalid objectAtIndex access on the cell info array when calling a reloadData on the gridView and inverting the row and columns quantity.
I have a single row with multiple columns displayed in landscape and want to have a single column with multiple rows when displayed in portrait.
On the reloadData call, removeCellWithInfo is called with a cell info containing an invalid x, y value with the new rows and cells quantity.
Has this just happened with the last version that was pushed or did the problem occur in previous versions? Cheers.
Hi, I'm using the latest code version.
I also noticed that I can reloadData without problem when going from 1 row of multiple columns (horizontal) to 1 column of multiple rows (vertical) but an exception is thrown when going the other way.
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
The problem is at:
- (void)checkViews { ... // Line 446 if ([[self.gridCells objectAtIndex:info.yPosition] count] - 1 > info.xPosition && info.frame.origin.x + info.frame.size.width < self.contentOffset.x + self.frame.size.width) ... } Jeff
Ran into this also with the latest version. A simple fix that seems to work is to add the line [cellInfoForCellsOnScreen removeAllObjects]; to initializeViews at line 534 just after the first for loop. See below: - (void)initialiseViews {
for (NSInteger i = 0; i < [cellInfoForCellsOnScreen count]; i++) {
DTGridViewCellInfo *info = [cellInfoForCellsOnScreen objectAtIndex:i];
if (![self cellInfoShouldBeOnShow:info])
[self removeCellWithInfo:info];
}
//Eric fix for issue with rotation of DTGridView to a table with a different number of rows or columns.
//Not sure if this should be the final fix, but it is working for now.
[cellInfoForCellsOnScreen removeAllObjects];
for (NSInteger i = 0; i < [gridCells count]; i++) {
I worked around this by adding a range check:
} else if (isGoingRight) {
// check bounds
if (info.yPosition < [self.gridCells count])
{
if ([[self.gridCells objectAtIndex:info.yPosition] count] - 1 > info.xPosition && info.frame.origin.x + info.frame.size.width < self.contentOffset.x + self.frame.size.width) {
if (![leftRightCells objectForKey:[NSString stringWithFormat:@"%i", info.yPosition]])
[leftRightCells setObject:info forKey:[NSString stringWithFormat:@"%i", info.yPosition]];
else if ([[leftRightCells objectForKey:[NSString stringWithFormat:@"%i", info.yPosition]] xPosition] < info.xPosition)
[leftRightCells setObject:info forKey:[NSString stringWithFormat:@"%i", info.yPosition]];
}
}
}
This happens for me as well on the current version - it happens when you remove a column, but not when you add one. Any thoughts on what makes for a performant workaround?