glyuck / GlyuckDataGrid

DataGridView (multicolumn tables) for iOS based on UICollectionView
MIT License
120 stars 35 forks source link

Cells disappearing from UICollectionView #14

Open ajayghodadra opened 6 years ago

ajayghodadra commented 6 years ago

Hi,

I know this library does not support self-sizing cells. To make it work with the dynamic width I am setting cell width based on the highest (longest) textLabel width based on sizeWithFont... method.

//Assuming max width = 200

 func dataGridView(_ dataGridView: DataGridView, widthForColumn column: Int) -> CGFloat {
        return dataSource.columnWidths[dataSource.header[column].key] ?? 0
    }
func dataGridView(_ dataGridView: DataGridView, heightForRow row: Int) -> CGFloat { 
    return dataSource.rows[row].max(by: {$1.height > $0.height})?.height ?? 0
}

For calculating height I am using max textLabel height for that particular row and applying it to each component of that row.

This works perfectly fine in most of the cases but sometimes the cells start disappearing randomly. It shows up again when I scroll up/down a bit.

I tried various solutions posted on community(http://ioscake.com/uicollectionviews-cell-disappearing.html) and came to a conclusion that this can only happen if layoutAttributesForElements(in rect: CGRect) returns wrong attributes.

In most cases it seems to happen only when the rows are more than 100..

@glyuck It there cance that layoutAttributesForElements returns false attributes? I would really appreciate if you could help me with this.