我使用下面的URL來設置我的imageView(位於路徑中)。是的,URL數據成功返回,但由於某種原因,我imageView保持空白(只是白色?)imageView設置爲URL時空白?
是的,我已經連接了我的imageView屬性...任何想法有什麼不對?我應該使用不同的代碼塊來完成這個任務嗎?
Viewcontroller.m
NSMutableDictionary *viewParamsDogs = [NSMutableDictionary new];
[viewParamsDogs setValue:@"mydogs" forKey:@"view_name"];
[DIOSView viewGet:viewParamsDogs success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.dogData = [responseObject mutableCopy];
[operation responseString];
NSDictionary *dic = [responseObject valueForKey: @"field_pet_photo_path"];
NSArray *arr = [dic valueForKey: @"und"];
NSDictionary *dic2= [arr objectAtIndex : 0];
NSString *path = [NSString stringWithFormat:@"%@", [dic2 valueForKey: @"safe_value"]];
NSLog(@"This is path %@", path);
if([path length]>0) {
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
self.dogimageView.image = image;
} else {
NSString *ImageURL = @"http://url.ca/paw.png";
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
self.dogimageView.image = [UIImage imageWithData:imageData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
路徑:
[5111:1673330] This is path (
"http://url.com/default/files/stored/1460659054.jpg"
)
的NSLog(@ 「這是路徑%@,%@」,路徑,NSStringFromClass(path.class) );回報:
2016-04-14 13:18:39.590 [5225:1700657] This is path (
"http://url.com/default/files/stored/1460659054.jpg"
), __NSCFString
URL是服務器還是文檔目錄? – Lion
@Lion服務器我相信? –
imageData中是否有任何數據?如果不是,那麼檢查你的網址是否有任何東西 –