2012-02-11 14 views
0

iOSのテーブルビューに2つの画像を配置する必要があります。UITableViewの複数の画像

私はセルに画像を配置するために、このコードを使用:

- (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; 
} 

ヘルプ?

答えて

1

独自のUITableViewCellサブクラスを作成したいと思うでしょう。その初期設定では、2つのUIImageViewを設定し、それらをサブビューとしてcontentViewに追加します。次に、layoutSubviewsで、あなたはそれらをレイアウトする方法に基づいてUIImageViewのフレームを設定します。

1
- (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; 
} 
+0

この作業中!ありがとうございます。 –

+0

UIImageViewを 'cell.contentView'に追加すると、私はあなたにアップビューします。セルのサブビューをcontentViewに移動して、セルのアクセサリビューを追加するときなどのストレッチ/シュリンクが正しく機能するようにします。 –

+0

@Matthias確実 – NeverBe