NSURL *url=[NSURL URLWithString:elementurl];
NSLog(@"url %@", url);
NSData *data = [NSData dataWithContentsOfURL:url];
NSLog(@"data = %@, length = %i", data, [data length]);
UIImage *image = [[UIImage alloc] initWithData:data];
[data release];
iam not getting the data can any one suggest another method
答案 0 :(得分:0)
- (无效)loadUserImage {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * frameImagePath = [profileInfoDict objectForKey:@“photo”];
imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:frameImagePath]]; if([imageData length] == 0){ / * NSString * imagePath = [[NSString alloc] initWithFormat:@“%@ /%@”,[[NSBundle mainBundle] resourcePath],@“no_image.png”]; UIImage image = [[UIImage alloc] initWithContentsOfFile:imagePath]; [item setObject:image forKey:@“itemImage”]; [imagePath发布]; [image release]; / } 其他{ [self performSelectorOnMainThread:@selector(imageget :) withObject:imageData waitUntilDone:NO];
} [池发布];
} - (void)imageget:(NSData *)数据 { UIImage * image = [[UIImage alloc] initWithData:data]; userImageImageView.contentMode = UIViewContentModeScaleAspectFit; userImage =图像; userImageImageView.image = image; [[mAppDelegate.userInfoArray objectAtIndex:1] setValue:image forKey:@“Image”];
}
答案 1 :(得分:0)
您使用的方法适用于小图像。如果您尝试下载大图像,则无法正常运行。
您可以使用以下代码
NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
建立连接
以上方法用于接收数据,错误处理等......
现在使用此方法应用您自己的逻辑。