我尝试在iphone应用中显示图像,但未显示。我在IB连接,我检查显示本地图像,它运作良好。我也检查从图像的网址,这是可以的。我用下面的代码:在uiimageview中显示来自url的图像
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
和
//Video.h
NSString *urlThumbnail;
,这是我的视图代码。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"URLTHUMBNAIL: %@", aVideo.urlThumbnail);
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
}
的NSLog上控制台getts
URLTHUMBNAIL: http://147.83.74.180/thumbnails/56.jpg
上IB的连接是好的,因为我可以使用在相同的IBAction为下一个代码显示的局部图像
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"barret" ofType:@"png"]];
代码看起来不错。再次检查您的IBoutlets,或发布更多代码。 – Jordan 2010-05-11 22:39:56
IBoutlet没问题。我在ViewDidAppear上写这个。 – nabrugir 2010-05-11 22:45:32