1

我创建了一个自定义 UITableViewCell 并向其中添加了 13 个 UIImageViews。在我的 cellForRowAtIndexPath 方法中,我为每个图像视图设置了图像(如果有可用的照片),但是当视图加载时,没有一个表格单元格显示其中的照片。但是,当我选择一个单元格时,所有图像都会加载。然后当我选择另一个单元格时,前一个单元格中的图像会消失,而我刚刚选择的单元格的图像会显示出来。下面是我的 cellForRowIndexPath 方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *tableCell = [self.tableView dequeueReusableCellWithIdentifier:@"photoSessionCell"];
    PhotoSessionCell * cell = (PhotoSessionCell*) tableCell;
    NSMutableArray *photos = [[self dataSource] objectAtIndex:[indexPath indexAtPosition:1]]; 

    for (int i = 0; i < 13; i++) {
        if (i < [photos count]) {
            UIImage * currImage = [photos objectAtIndex:i];
            switch (i) {
                case 0:
                    [[cell image1] setImage:currImage];
                    break;
                case 1:
                    [[cell image2] setImage:currImage];
                    break;
                case 2:
                    [[cell image3] setImage:currImage];
                    break;
                case 3:
                    [[cell image4] setImage:currImage];
                    break;
                case 4:
                    [[cell image5] setImage:currImage];
                    break;
                case 5:
                    [[cell image6] setImage:currImage];
                    break;
                case 6:
                    [[cell image7] setImage:currImage];
                    break;
                case 7:
                    [[cell image8] setImage:currImage];
                    break;
                case 8:
                    [[cell image9] setImage:currImage];
                    break;
                case 9:
                    [[cell image10] setImage:currImage];
                    break;
                case 10:
                    [[cell image11] setImage:currImage];
                    break;
                case 11:
                    [[cell image12] setImage:currImage];
                    break;
                default:
                    [[cell image13] setImage:currImage];
                    break;
            }
        } else {
            break;
        }
    }

    NSDate* date = [[self dates] objectAtIndex:[indexPath indexAtPosition:0]];
    NSDateFormatter * format  = [[NSDateFormatter alloc] init];
    [format setDateStyle:NSDateFormatterLongStyle];
    [[cell textLabel] setText:[format stringFromDate:date]];

    return cell;
}
4

0 回答 0