Cells in last row never get requested #8

mbarlocker opened this Issue Jan 29, 2011 · 2 comments


None yet
2 participants

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;


    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.

For the time being, I am just going to always return 4 columns, and then when the cell is requested, I will return an uncustomized DTGridViewCell. This seems to work.

Any updates regarding this issue?

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