AQGridView icon indicating copy to clipboard operation
AQGridView copied to clipboard

Infinite Loop if cell.width > view.width

Open jonruiz opened this issue 14 years ago • 1 comments

If layout is vertical and the desires cell width returned by the delegate is greater than the view's width, then there will be an infinite loop while trying to lay things out. I tracked it down to here and made the following change. The view will get cut off, but the infinite loop is avoided:

  • (void) fixDesiredCellSizeForWidth: (CGFloat) width { // Much thanks to Brandon Sneed (@bsneed) for the following new algorithm, reduced to two floating-point divisions -- that's O(1) folks! CGFloat w = floorf(width - _leftPadding - _rightPadding); CGFloat dw = floorf(_desiredCellSize.width); CGFloat multiplier = floorf( w / dw );

    // CHANGED: to avoid infinite loop if (0 == multiplier) multiplier = 1; // CHANGED: end changes

    _actualCellSize.width = floorf( w / multiplier ); _actualCellSize.height = _desiredCellSize.height; }

jonruiz avatar Oct 27 '11 22:10 jonruiz

great catch!

bsneed avatar Oct 27 '11 22:10 bsneed