【发布时间】:2012-09-07 22:59:23
【问题描述】:
我想将NSMutableArray 中的图片添加到表格视图中的自定义单元格中。每个单元格中将有四个或更多图像。所以这是我的问题:
如果我引用 indexPath.row,自定义单元格将如下所示:
单元格1:图片1、图片2、图片3、图片4
单元格 2:图片 2、图片 3、图片 4、图片 5
单元格3:图片3、图片4、图片5、图片6
但我想要:
单元格1:图片1、图片2、图片3、图片4
单元格2:图片5、图片6、图片7、图片8
单元格3:图片9、图片10、图片11、图片12
我是 xCode 的新手,我没有看到好的解决方案。
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ImageCustomCell";
ImageCustomCell *cell = (ImageCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCustomCell" owner:nil options:nil];
for(id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (ImageCustomCell *) currentObject;
break;
}
}
}
// here i get the indexPath.row for every cell and add +1 - +3 to it to get the next image, but every new cell just get +1, not +4
cell.imageForCell.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:indexPath.row]];
cell.imageForCell2.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:indexPath.row+1]];
cell.imageForCell3.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:indexPath.row+2]];
cell.imageForCell4.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:indexPath.row+3]];
return cell;
}
【问题讨论】:
标签: ios uitableview uiimage nsmutablearray