Skip to content

didSelectItemAtIndex:(NSUInteger)index not working properly #210

@Joshua4550

Description

@Joshua4550

I have a basic gridview setup with a basic custom cell (one image, one label). The didSelect method works fine until I introduce a variable Cell Identifier.

One cell identifier will use a frame of 50% width, and the second identifier will use a width of 100%. The 50% Identifier is used in all cases, except for when the datasource count is odd and it is currently the last grid item (ie, two columns until the last item then one column).

The cells are rendered perfectly fine, but when it comes to clicking.. all the 50% ones work, and the 100% width item does not even recognise it is being clicked - nothing!

Test Code... (cellForItemAtIndex)

static NSString *CellIdentifier = @"HalfGridCellIdentifier";
static NSString *CellIdentifier2 = @"FullGridCellIdentifier";
ThumbnailGridCell *cell;

/**
 * Odd number of rows, so the last row should always be full width
 */
if (datasource.count > 0 && datasource.count % 2 && index == datasource.count - 1) {
    cell = [[ThumbnailGridCell alloc] initWithFrame: CGRectMake(0, 0, aGridView.frame.size.width, gridSize.height) reuseIdentifier: CellIdentifier2];
}
/**
 * Even number of rows or not last row, so half width
 */
else {
    cell = (ThumbnailGridCell *)[aGridView dequeueReusableCellWithIdentifier: CellIdentifier];
    if (cell == nil) {
        cell = [[ThumbnailGridCell alloc] initWithFrame: CGRectMake(0, 0, gridSize.width, gridSize.height) reuseIdentifier: CellIdentifier];
    }
}

Test Code (didSelectItemAtIndex):

NSLog(@"clicked item %d", index);

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