Skip to content

Instantly share code, notes, and snippets.

@inonb
Created July 22, 2012 02:52
[iOS] アイコンをURLから取得する
// アイコンのプレースホルダを設定
cell.imageView.image = [UIImage imageNamed:@"placeholder"];
// アイコンのURLからリクエストを作る
NSString *iconURLString = [[[item objectForKey:@"im:image"] objectAtIndex:0] objectForKey:@"label"];
NSURL *iconURL = [NSURL URLWithString:iconURLString];
NSURLRequest *request = [NSURLRequest requestWithURL:iconURL];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
// 取得した画像データをセルに設定
UIImage *iconImage = [[UIImage alloc] initWithData:data];
cell.imageView.image = iconImage;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment