如何为tableview的每个单元格设置不同的图像

Tos*_*eef 2 iphone

如何为表视图的每个单元格设置不同的图像.我想通过图像名称数组来做到这一点

Nit*_*Nit 6

使用以下代码......

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

/* Initialise the cell */

static NSString *CellIdentifier = @"MyTableViewCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

/* Configure the cell */

NSString *cellImageName = [[self cellImageNames] objectAtIndex:[indexPath row]];//cellImageNames ism image names array where 
UIImage *cellImage = [UIImage cellImageName];
[[cell imageView] setImage:cellIcon];

// Other cell configuration code...

return cell;
}
Run Code Online (Sandbox Code Playgroud)

希望对你有帮助...


Qui*_*rin 5

例如:

cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%i.png", indexPath.row]];
Run Code Online (Sandbox Code Playgroud)

要么

cell.imageView.image = (UIImage *)[yourArray objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)


Rav*_*avi 5

您的解决方案是在这里链接 如何在UITableView中添加UIImage

- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *MyIdentifier = @"MyIdentifier";
     MyIdentifier = @"TableView";

     MainView *cell = (MainView *)[tableView  dequeueReusableCellWithIdentifier: MyIdentifier];
     if(cell == nil) {
          [[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self   options:nil];
           cell = tableCell;
        }

  [cell LabelText:[arryList objectAtIndex:indexPath.row]];
 [cell ProductImage:[imagesList objectAtIndex:indexPath.row]];
  return cell;
  }
Run Code Online (Sandbox Code Playgroud)

Uitableview与图像显示像

在此输入图像描述