1
我有一個名爲http
的對象,它從php腳本(它是圖像的URL)中檢索一個字符串。將對象NSData中的圖像加載到UIImageView中
在課堂上,我把它加載到一個NSData成員如下:
profileImageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:result]];
result
是URL字符串,已被選中。
並加載它在我的視圖控制器:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
NSLog(@"appeared");
http = [[HTTP alloc] init];
[http getProfileImage:[SignInViewController getUsernameString]];
NSLog(@"data: %@",http.profileImageData);
profileImageView.image = [UIImage imageWithData:http.profileImageData];
}
我得到的錯誤:
2012-03-01 11:03:16.865 Träffa[5574:f803] data: (null)
2012-03-01 11:03:16.878 Träffa[5574:f803] Error receiving response: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6b7c840 {NSUnderlyingError=0x6b7c2c0 "bad URL", NSLocalizedDescription=bad URL}
這是爲什麼返回null?
編輯:我將問題範圍縮小到這一點:
NSLog(@"%@",result);
profileImageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:result]];
NSLog(@"%@",profileImageData);
第一的NSLog與地址返回,上NSData的第二個返回null。我正確地寫這篇文章嗎?
並獲得NSURLErrorDomain代碼,你應該檢查的第一件事是您選擇的網址。 – peko 2012-03-01 16:32:53