1

セルをクリックしたときに画像を変更しようとしていますが、機能していません

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath
{
    UITableViewCell *cell = [feedsTableView cellForRowAtIndexPath:indexPath];

UILabel *title = (UILabel *)[cell.contentView viewWithTag:0011];
UIImage *image = (UIImage *)[cell.contentView viewWithTag:0017];

image = [UIImage imageNamed:@"reload.png"];
title.text = @"test";

cellClicked = YES;

[feedsTableView beginUpdates];
[feedsTableView endUpdates];

[feedsTableView deselectRowAtIndexPath:indexPath animated:YES];

}

ただし、タイトルは変更されます。

テーブル内に画像を追加する方法。

CGRect imageFrame = CGRectMake(0, 0, 120, 90);
    customImage.tag = 0017;
    self.customImage = [[UIImageView alloc] initWithFrame:imageFrame];
    [cell.contentView addSubview:self.customImage];
4

3 に答える 3

0

テーブル ビューからビューを追加するのではなく、カスタムの UITableViewCell を使用してみませんか?

そうすれば、セルのプロパティとしてラベルと画像ビューを設定するだけで、この問題全体を回避できるため、タグの使用を避けることができます。

また、ラベルと画像ビューを毎回設定する必要がなく、セルと共に再利用されるため、パフォーマンスがわずかに向上します。

于 2013-07-03T14:07:57.053 に答える