我有以下代码:
-(void) viewDidAppear:(BOOL)animated {
AsyncImageView *weatherImageView = [[AsyncImageView alloc] initWithFrame:weatherImage.frame];
NSString *myString = @"http://openweathermap.org/img/w/10d.png";
NSString *url = [NSString stringWithString:myString];
NSLog(@"The complete url is %@", url);
[weatherImageView loadImageFromURL:url];
[self.weatherImage addSubview:weatherImageView];
}
图片网址一切正常,但视图显示时图片不会显示。
但是如果我用同样的方法写下面这行
-(void) viewDidAppear: (BOOL) animated {
[self.weatherImage setImage:[UIImage imageNamed:[UIImage imageNamed:"background.png"]]];
}
我看到" background.png"在ImageView中显得很整洁。
想知道第一个代码有什么问题。
答案 0 :(得分:1)
loadImageFromURL
期待NSURL。不是NSString:
AsyncImageView *weatherImageView = [[AsyncImageView alloc] initWithFrame:weatherImage.frame];
NSString *myString = @"http://openweathermap.org/img/w/10d.png";
NSURL *url = [NSURL URLWithString:myString];
NSLog(@"The complete url is %@", url);
[weatherImageView loadImageFromURL:url];