tableview
セルがを使用する場所がありright detail layout
ます。私が今やりたいのは、ユーザーがセルを選択したときです。そのセルに画像を追加する必要がありますか?
これをどのように実装すべきか提案はありますか?
敬具
tableview
セルがを使用する場所がありright detail layout
ます。私が今やりたいのは、ユーザーがセルを選択したときです。そのセルに画像を追加する必要がありますか?
これをどのように実装すべきか提案はありますか?
敬具
これは-tableView:didSelectForRowAtIndexPath:
、ユーザーが画像ビューを作成して追加できることを選択したときに実行できます。
これを実装してみてください
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:@"imageName"];
}
画像がどこに保持されているかについての詳細は提供されていません。
画像が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];
幸運を ...!!!
UITableViewCell のサブクラスを作成できます。次に、メソッド-touchBeginを実装し、必要なことを行います