我创建了一个自定义的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;
}