Skip to content
This repository was archived by the owner on May 8, 2020. It is now read-only.
This repository was archived by the owner on May 8, 2020. It is now read-only.

Cells in last row never get requested #8

@mbarlocker

Description

@mbarlocker

I've got a grid 4 columns by R rows. I'm filling this grid with data such that each row might be only partially filled - 3 out of the 4 columns for example. Only 2 rows are on screen at any time (except during scrolling). It is a normal DTGridView that scrolls vertically.

The problem occurs when I have 4 rows. The first 3 are completely full (4/4 columns), and the last row is only partially full (1/4 columns). The DTGridView allows me to scroll to the 4th row, but the cell in the 4th row, 1st column never appears. I put logging statements in the gridView:viewForRow:column: method, and the cell is never even asked for.

Here's my pseudo code

  • (NSInteger)numberOfRowsInGridView:(DTGridView *)gridView {
    NSUInteger itemCount = ;
    return ceil((double)itemCount / (double)GRID_VIEW_NUM_VISIBLE_COLUMNS);
    }

  • (NSInteger)numberOfColumnsInGridView:(DTGridView *)gridView forRowWithIndex:(NSInteger)index {
    NSUInteger itemCount = ;
    NSUInteger rows = [self numberOfRowsInGridView:gridView];
    NSUInteger numItemsIfFilled = GRID_VIEW_NUM_VISIBLE_COLUMNS * rows;
    BOOL lastRow = (index == rows - 1);
    BOOL gridFull = itemCount == numItemsIfFilled;

    NSInteger columns = GRID_VIEW_NUM_VISIBLE_COLUMNS;

    if (lastRow && !gridFull) {
    columns = itemCount % GRID_VIEW_NUM_VISIBLE_COLUMNS;
    }

    return columns
    }

  • (CGFloat)gridView:(DTGridView *)gridView heightForRow:(NSInteger)rowIndex {
    return gridView.frame.size.height / GRID_VIEW_NUM_VISIBLE_ROWS;
    }

  • (CGFloat)gridView:(DTGridView *)gridView widthForCellAtRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {
    return gridView.frame.size.width / GRID_VIEW_NUM_VISIBLE_COLUMNS;
    }

  • (DTGridViewCell *)gridView:(DTGridView *)gridView viewForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {
    return ;
    }

One thing to note is that when the number of rows fits on screen, the last row shows just fine. It is only when the last row does not fit on screen that it is not requested at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions