NSMutableArray
テーブルビューのカスタムセルに画像を追加したい。すべてのセルに4つ以上の画像があります。だからここに私の問題があります:
カスタムセルを参照するとindexPath.row
、次のようになります。
cell1:picture1、
picture2
、picture3、picture4 cell2:picture2、picture3、picture4、picture5 cell3:picture3、picture4、picture5、picture6
でも私はしたい:
cell1: picture1、picture2、picture3、picture4 cell2:picture5
、picture6、picture7、picture8
cell3:picture9、 picture10、picture11、picture12
私は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;
}