Invalid array access when changing grid orientation #4

Open
jfmorin opened this Issue Dec 13, 2010 · 5 comments

Comments

Projects
None yet
5 participants
@jfmorin

jfmorin commented Dec 13, 2010

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.

@danielctull

This comment has been minimized.

Show comment Hide comment
@danielctull

danielctull Dec 13, 2010

Owner

Has this just happened with the last version that was pushed or did the problem occur in previous versions? Cheers.

Owner

danielctull commented Dec 13, 2010

Has this just happened with the last version that was pushed or did the problem occur in previous versions? Cheers.

@jfmorin

This comment has been minimized.

Show comment Hide comment
@jfmorin

jfmorin Dec 13, 2010

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

jfmorin commented Dec 13, 2010

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
@eric-w

This comment has been minimized.

Show comment Hide comment
@eric-w

eric-w Dec 27, 2010

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++) {

eric-w commented Dec 27, 2010

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++) {
@quimarche

This comment has been minimized.

Show comment Hide comment
@quimarche

quimarche Jul 5, 2011

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]];
            }                
        }
    }

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]];
            }                
        }
    }
@apike

This comment has been minimized.

Show comment Hide comment
@apike

apike Aug 30, 2011

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?

apike commented Aug 30, 2011

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?

apike added a commit to apike/DTGridView that referenced this issue Aug 30, 2011

th-in-gs added a commit to th-in-gs/DTGridView that referenced this issue Mar 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment