Created
July 22, 2012 02:52
[iOS] アイコンをURLから取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// アイコンのプレースホルダを設定 | |
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