Iphone UITableView上有多个图像

Iphone UITableView上有多个图像,iphone,ios,image,ipad,uitableview,Iphone,Ios,Image,Ipad,Uitableview,我需要在iOS tableview中放置两个图像 我使用此代码将图像放置在单元格中: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWit

我需要在iOS tableview中放置两个图像

我使用此代码将图像放置在单元格中:

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

static NSString *CellIdentifier = @"Cell";

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

UIImage *cellImage = [UIImage imageNamed:@"verde_diversos.png"];
cell.imageView.image = cellImage;
cell.textLabel.text = [self.colorNames objectAtIndex: [indexPath row]]; 

return cell;
}

帮助?

您需要创建自己的
UITableViewCell
子类。在它的初始化器中,您可以设置两个
UIImageView
s,并将它们作为它的子视图添加到
contentView
。然后在
layoutSubviews
中,您将根据您希望的布局方式设置
UIImageView
s的框架。

如果您将UIImageView添加到
单元格中。contentView
我将向上投票。单元格的子视图应进入contentView,以便单元格的拉伸/收缩(例如,添加accessoryView时)正常工作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

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

UIImageView *cellView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)] autorelease];
cellView.tag = 555;

[cell.contentView addSubview:cellView];
}

UIImage *cellImage = [UIImage imageNamed:@"verde_diversos.png"];
cell.imageView.image = cellImage;
cell.textLabel.text = [self.colorNames objectAtIndex: [indexPath row]]; 

UIImageView *secondImage = [cell.contentView viewWithTag:555];
secondImage.image = [UIImage imageNamed:@"logo.png"];

return cell;
}