AQGridView选择单元格

时间:2012-06-13 22:38:42

标签: ios aqgridview

我创建了一个自定义AQGridViewCell,如下所示:

- (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;
}

我在你选择单元格时添加了这个方法:

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

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

}

如何访问storyIDcell内的gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index

1 个答案:

答案 0 :(得分:3)

将您的didSelectItemAtIndex更新为以下

- (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);
}