Search code examples
iosaqgridview

AQGridView Select Cell


I create a custom AQGridViewCell like so:

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * PlainCellIdentifier = @"PlainCellIdentifier";

GridViewCell * cell = (GridViewCell *)[aGridView dequeueReusableCellWithIdentifier:@"PlainCellIdentifier"];

if ( cell == nil )
{
    cell = [[GridViewCell alloc] initWithFrame: CGRectMake(3.333, 3.3336, 100, 100)
                               reuseIdentifier: PlainCellIdentifier];
}
NSString *stringURL = [[featuredStories objectAtIndex:index] objectAtIndex:1];
NSLog(@"stringURL: %@", stringURL);
NSURL *url = [NSURL URLWithString:stringURL];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"example0.png"]];
cell.storyID = [[featuredStories objectAtIndex:index] objectAtIndex:0];
return cell;
}

and I have added the method when you select the cell like so:

- (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index {

//I want to NSLog the cell.storyID here
NSLog (@"Selected theArgument=%d\n", index);

}

how do I go about accessing the storyID within the cell in gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index ?


Solution

  • Update your didSelectItemAtIndex to the following

    - (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index {
    
        //Get the cell at the selected index
        GridViewCell * cell = (GridViewCell *)[grid cellForItemAtIndex:index];
        NSLog(@"Story Id = %@", cell.storyID);
    }