Ios5 向上滚动GMGridView&;后,ImageView中的图像将交换;在iphone中

Ios5 向上滚动GMGridView&;后,ImageView中的图像将交换;在iphone中,ios5,reusability,gmgridview,Ios5,Reusability,Gmgridview,我在GMGridView中添加了UIImageView,因为我想在网格中显示图像。在网格中添加imageview后,所有这些都可以正常工作。我想在第一行和第一列显示不同的图像。所以我在和索引比较后设置了这个图像。 但当我上下滚动时,它会将图像从第一列更改为第二列或第三列。第6行或第7行也显示了相同的图像。这出了什么问题?这是我的密码 - (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSIn

我在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子视图]makeObjectsPerformSelector:@selector(removeFromSuperview)]? 有人能帮我吗?谢谢

尝试使用该代码

- (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)];
    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)];    
    cell.contentView = imageView;

}
return cell;
}

我认为问题可能是您正在使用
makeObjectsPerformSelector
删除单元格,然后在删除后再也不会添加它,因为由于实例
单元格的存在,控件可能不会进入条件
if(!cell){}
。 希望这对你有帮助