我在 GMGridView 中添加了 UIImageView,因为我想在网格中显示图像。在网格中添加 imageview 后,一切正常。我想在第一行和第一列显示不同的图像。所以我在与索引比较后设置了该图像。但是当我向上和向下滚动时,它会将图像从第一列更改为第二列或第三列。同样的图像显示在第 6 行或第 7 行。这有什么问题?这是我的代码
- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index
{
CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
GMGridViewCell *cell = [gridView dequeueReusableCell];
UIImageView *imageView = nil;
if (!cell)
{
cell = [[GMGridViewCell alloc] init];
cell.deleteButtonIcon = [UIImage imageNamed:@"close_x.png"];
cell.deleteButtonOffset = CGPointMake(-15, -15);
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
cell.contentView = imageView;
}
NSLog(@"Project Index value:- %d",index);
if (index == 0) {
imageView.image = [UIImage imageNamed:@"add.png"];
}
else{
imageView.image = [UIImage imageNamed:@"face.png"];
}
[[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
return cell;
}
我还需要 [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; ? 有谁能够帮我 ?谢谢