0

tableviewセルがを使用する場所がありright detail layoutます。私が今やりたいのは、ユーザーがセルを選択したときです。そのセルに画像を追加する必要がありますか?

これをどのように実装すべきか提案はありますか?

敬具

4

4 に答える 4

1

これは-tableView:didSelectForRowAtIndexPath:、ユーザーが画像ビューを作成して追加できることを選択したときに実行できます。

于 2013-03-04T11:03:16.673 に答える
0

これを実装してみてください

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:@"imageName"];
}
于 2013-03-04T11:33:00.920 に答える
0

画像がどこに保持されているかについての詳細は提供されていません。

画像がCache Directoryにある場合は、次のように記述する必要があります-didSelectRowAtIndexPath...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[paths lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"Image-%d.png",indexPath.row]]];
yourImageView = [[UIImageView alloc] initWithImage:image];
[cell addSubView;yourImageView];

サーバーから画像をダウンロードする場合、コードは次のようになります。

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://yourURL.com"]]]; 
UIImage *image = [[UIImage alloc] initWithData:data];
yourImageView = [[UIImageView alloc] initWithImage:image];
[cell addSubView;yourImageView];

幸運を ...!!!

于 2013-03-04T11:20:59.053 に答える
0

UITableViewCell のサブクラスを作成できます。次に、メソッド-touchBeginを実装し、必要なことを行います

于 2013-03-04T12:44:49.103 に答える