我正在尝试实现一个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项,但是日志只打印最多11项,不管我滚动了多少,12项之后的标签从一开始就重复了。有什么建议吗?
发布于 2013-11-26 10:05:25
试试这个..。
-(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;
}https://stackoverflow.com/questions/20213746
复制相似问题