我想從NSMutableArray
添加圖片到tableview中的自定義單元格。每個單元格中將有四個或更多圖像。因此,這裏是我的問題:如何添加多個圖片到具有標籤或標識符的自定義tableviewcells
如果我指的是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;
}
太容易了!謝謝! – myr0
不客氣!這有助於解決問題嗎?還是需要進一步的幫助? –
是的,非常幫助我。但它更簡單,然後:cell.imageForCell.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:(indexPath.row * 1)]];和 cell.imageForCell.image = [UIImage imageWithContentsOfFile:[imagePathArray objectAtIndex:(indexPath.row * 2)]];等等.. – myr0