0

这是我的表格视图单元格加载代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:self options:nil];
        cell = nibLoadedCell;
    }

    if (photosArray.count > 0) {
        for (int i = 1; i < 4; i++) {                
            UIButton *button = (UIButton *)[cell viewWithTag:i];
            [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
            button.layer.borderWidth = 2;
            button.layer.cornerRadius = 5;
            button.clipsToBounds = YES;

            //Add images to the button
            UIImage *btnImg;
            if ((indexPath.row * 3) + i < photosArray.count) {
                btnImg = [photosArray objectAtIndex:((indexPath.row) * 3 + i)];
                NSLog(@"%d",(indexPath.row) * 3 + i);
            }

            [button setBackgroundImage:btnImg forState:UIControlStateNormal];
            button.tag = imageButtonTag;
            imageButtonTag--;                
        }
    }
    NSLog(@"%d",cell.contentView.subviews.count);
    for (UIButton *button in cell.contentView.subviews) {

        if ([button backgroundImageForState:UIControlStateNormal] == nil) {
            [button removeFromSuperview];
        }
    }

    return cell;    
}

我已经创建了一个包含 3 个按钮的自定义单元格。

我也有一系列不同的图像。

上面的代码应该在每个单元格上创建一个带有 3 个按钮/的表格视图,并且每个按钮上面都有一个背景图像。

问题是,当向下滚动时,我看到一些图像重复它们自己。这不可能来自照片的源数组,我 99% 确定我的数组没问题。

有人能看到我在做什么错吗?我一直在看它这么久,我看不出我的错误..

谢谢

4

0 回答 0