由于 AQGridview 从 UITableView 借用了很多它的想法,所以我认为答案应该适用于两者。
我有一个自定义单元格,里面有以下对象:
- 标签
- 最喜欢的按钮(可以由用户打开/关闭,我使用 .selected = YES/NO)
问题是滚动时保持按钮的状态。下面是我的“cellForItemAtIndex”方法。
- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * cellIdentifier = @"CellIdentifier";
SampleGridViewCell * cell = (SampleGridViewCell *)[aGridView dequeueReusableCellWithIdentifier:cellIdentifier];
if ( cell == nil )
{
cell = [[SampleGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200, 60) reuseIdentifier: cellIdentifier];
}
NSDictionary *item = [self.items objectAtIndex:index];
NSString *title = [item objectForKey:@"title"];
cell.index = index;
cell.titleLabel.text = title;
//cell.favButton.selected = (logic goes here);
return cell;
}
不知何故,我需要在我的视图控制器中保留一个项目何时被收藏的参考,以便我可以在此方法中重新创建单元格时打开/关闭按钮。
我是否使用 vc 中的方法在 cell.favButton 上执行 addTarget?但是,我如何获得对按钮索引的引用呢?
有人实现了类似的东西吗?