我正在尝试实现一个3Xn网格视图,目前我正在使用AQGridView类,它工作正常,但唯一的问题是滚动数据重复,就像在tableView中一样,在tableView中我用来处理这个问题使用此代码
NSUInteger row = 0;
NSUInteger sect = indexPath.section;
for (NSUInteger i = 0; i < sect; ++ i)
row += [self tableView:tableView numberOfRowsInSection:i];
row += indexPath.row;
我想知道是否有相似的解决方案。这是我当前的网格视图代码
- (AQGridView *) gridView {
if (![self isViewLoaded])
return nil;
AQGridView * const gv = (AQGridView *)_groupGridView;
NSCParameterAssert([gv isKindOfClass:[AQGridView class]]);
return gv;
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSUInteger) numberOfItemsInGridView: (AQGridView *) gridView
{
return [selectedList count];
}
- (AQGridViewCell *) gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index {
static NSString * const identifier = @"Cell";
NTGridViewCell *cell = (NTGridViewCell *)[gridView dequeueReusableCellWithIdentifier:identifier];
if (cell)
NSCParameterAssert([cell isKindOfClass:[NTGridViewCell class]]);
if (!cell) {
CGRect cellFrame = (CGRect){
CGPointZero,
gridView.gridCellSize
};
cell = [NTGridViewCell cellFromNib];
cell.reuseIdentifier = identifier;
cell.frame = cellFrame;
cell.delegate=self;
cell.userName.text=[[selectedList objectAtIndex:index] valueForKey:@"name"];
NSLog(@"number:%d,name:%@",index,[[selectedList objectAtIndex:index] valueForKey:@"name"]);
cell.contentView.superview.backgroundColor=[UIColor clearColor];
return cell;
}
我的selectedList中有26个项目,但是无论我滚动多少以及12个项目从开始重复后的标签,日志都会打印最多11个数字。有什么建议吗?
答案 0 :(得分:0)
试试这个......
-(AQGridViewCell *) gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
{
static NSString * const identifier = @"Cell";
NTGridViewCell *cell = (NTGridViewCell *)[gridView dequeueReusableCellWithIdentifier:identifier];
if (cell)
NSCParameterAssert([cell isKindOfClass:[NTGridViewCell class]]);
if (!cell)
{
CGRect cellFrame = (CGRect){
CGPointZero,
gridView.gridCellSize
};
cell = [NTGridViewCell cellFromNib];
cell.reuseIdentifier = identifier;
cell.frame = cellFrame;
cell.delegate=self;
}
cell.userName.text=[[selectedList objectAtIndex:index] valueForKey:@"name"];
NSLog(@"number:%d,name:%@",index,[[selectedList objectAtIndex:index] valueForKey:@"name"]);
cell.contentView.superview.backgroundColor=[UIColor clearColor];
return cell;
}