nlampi / SwiftGridView

Swift based data grid view.
MIT License
58 stars 15 forks source link

Crash when attempting to scroll into frozen column #39

Closed robcecil closed 5 years ago

robcecil commented 6 years ago

When attempting to call SwiftGridView.scrollToCellAtIndexPath when there are two frozen columns, and using an IndexPath whose sgColumn is equal to 1, the Layout method horizontalOffset(for:atColumn:atScrollPosition) will crash:

    func horizontalOffset(for indexPath: IndexPath, atColumn column: Int, atScrollPosition scrollPosition: UICollectionViewScrollPosition) -> CGFloat {
        var offset: CGFloat = 0.0

        if (column > 0) {
            for columnIndex: Int in self.frozenColumnsCount ..< column {
                offset += self.zoomModifiedValue(self.layoutDelegate.collectionView(self.collectionView!, layout: self, widthOfColumnAtIndex: columnIndex))
            }
        }

        if scrollPosition.contains(.right) {
            offset += self.zoomModifiedValue(self.layoutDelegate.collectionView(self.collectionView!, layout: self, widthOfColumnAtIndex: column))
        } else if scrollPosition.contains(.centeredHorizontally) {
            offset += self.zoomModifiedValue(self.layoutDelegate.collectionView(self.collectionView!, layout: self, widthOfColumnAtIndex: column)) / 2
        }

        return offset
    }

image

In this case self.frozenColumnsCount == 2, and column is 1.

nlampi commented 6 years ago

Added a quick fix in v0.6.5. All looks to be working fine from my testing now. I'll keep looking for any other issues with this.