I would like to get an image from an URL and put it into a NSArray, but doesn't work in the below codes, please help:
#interface DataViewController ()
#property (readonly, strong, nonatomic) NSArray *picData;
#end
#implementation DataViewController
- (void)viewDidLoad {
NSString *imageUrlStringAA=#"http://aaa.net/AA.png";
NSString *imageUrlStringBB=#"http://aaa.net/BB.png";
NSURL *urlAA=[NSURL URLWithString:imageUrlStringAA];
NSURL *urlBB=[NSURL URLWithString:imageUrlStringBB];
NSData *dataAA=[[NSData alloc] initWithContentsOfURL:urlAA];
NSData *dataBB=[[NSData alloc] initWithContentsOfURL:urlBB];
UIImage *imageAA=[UIImage imageWithData:dataAA];
UIImage *imageBB=[UIImage imageWithData:dataBB];
_picData = [NSArray arrayWithObjects:imageAA, imageBB, nil];
Any ideas is appreciated, thank you.
First thing for download anything from http protocol then Add following diction in info.plist
And now try this code:
#interface DataViewController ()
#property (readonly, strong, nonatomic) NSArray *picData;
#end
#implementation DataViewController
- (void)viewDidLoad {
NSString *imageUrlStringAA=#"http://www.hdwallpapers.in/download/antelope_canyon-360x640.jpg";
NSString *imageUrlStringBB=#"http://www.hdwallpapers.in/download/vegeta_dragon_ball_super-360x640.jpg";
NSURL *urlAA=[NSURL URLWithString:imageUrlStringAA];
NSURL *urlBB=[NSURL URLWithString:imageUrlStringBB];
NSData *dataAA=[[NSData alloc] initWithContentsOfURL:urlAA];
NSData *dataBB=[[NSData alloc] initWithContentsOfURL:urlBB];
UIImage *imageAA=[UIImage imageWithData:dataAA];
UIImage *imageBB=[UIImage imageWithData:dataBB];
_picData = [NSArray arrayWithObjects:imageAA, imageBB, nil];
}
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:#"Image URL"]]];
dispatch_sync(dispatch_get_main_queue(), ^{
if(image!= nil){
[[cell myimage] setImage:image];
}else{
UIImage * image = [UIImage imageNamed:#"PLACEHOLDER"];
[[cell myimage] setImage:image];
}
[cell setNeedsLayout];
});
});
Try these...
Related
hello guys i am downloading images for each product from my server and set it up inside a custom cell of my UITableView and caching them on disk after scrolling down the UITableView images are miss placed what i mean the new cells takes the old values of the previous cells after searching of this topic i found different solution either to use prepareForReuse or checking on the cell if its nil or not both of them does not fit my case.
CODE:
MyCustomCell.h
#import <UIKit/UIKit.h>
#import "mirsaProduct.h"
#import "SVProgressHUD.h"
#import "AFNetworking.h"
#import "UIWebView+AFNetworking.h"
#import "SDWebImageCompat.h"
#import "SDWebImageDownloaderOperation.h"
#import "SDWebImageDownloader.h"
#import "SDImageCache.h"
#import "SDWebImageDownloaderOperation.h"
#import "SDWebImageManager.h"
#import "SDWebImageDecoder.h"
#import "SDWebImagePrefetcher.h"
#interface mirsaProductTableViewCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UILabel *mirsaProductTitle;
#property (weak, nonatomic) IBOutlet UITextView *mirsaProductDescription;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *mirsaProductActivityIndicatorView;
#property (weak, nonatomic) IBOutlet UIImageView *mirsaProductLogoImageView;
#end
**MyCustomCell.m**
#import "mirsaProductTableViewCell.h"
#implementation mirsaProductTableViewCell
#synthesize mirsaProductTitle = _mirsaProductTitle;
#synthesize mirsaProductDescription = _mirsaProductDescription;
#synthesize mirsaProductLogoImageView = _mirsaProductLogoImageView;
#synthesize mirsaProductActivityIndicatorView = _mirsaProductActivityIndicatorView;
-(void)prepareForReuse
{
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
myTableViewController.h
#import <UIKit/UIKit.h>
#import "mirsaCategories.h"
#import "sharedManagers.h"
#import "mirsaProductTableViewCell.h"
#import "constant.h"
#import "SVProgressHUD.h"
#import "AFNetworking.h"
#import "UIWebView+AFNetworking.h"
#import "SDWebImageCompat.h"
#import "SDWebImageDownloaderOperation.h"
#import "SDWebImageDownloader.h"
#import "SDImageCache.h"
#import "SDWebImageDownloaderOperation.h"
#import "SDWebImageManager.h"
#import "SDWebImageDecoder.h"
#import "SDWebImagePrefetcher.h"
#import "mirsaProduct.h"
#import "mirsaDetailedProductViewController.h"
#import "mirsaProductDetailsTableViewController.h"
#interface mirsaProductsTableViewController : UITableViewController
#property (nonatomic,strong) mirsaCategories *currentCategory;
#property (nonatomic,strong) NSMutableArray *listOfProducts;
#property (nonatomic,strong) mirsaProduct *currentProduct;
#end
myTableViewController.m
due to not make the question too long i just import the cellOfRowAtIndexPath and the relevant method to it.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"mirsaProductCell";
mirsaProductTableViewCell *cell = (mirsaProductTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[mirsaProductTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] ;
cell.mirsaProductLogoImageView.layer.cornerRadius = 50.0f;
cell.mirsaProductLogoImageView.layer.borderWidth = 1.5f;
cell.mirsaProductLogoImageView.clipsToBounds = YES;
cell.mirsaProductLogoImageView.layer.borderColor = [UIColor colorWithRed:redRedColor green:redGreenColor blue:redBlueColor alpha:ALFA].CGColor;
mirsaProduct *currentProduct = [self.listOfProducts objectAtIndex:indexPath.row];
cell.mirsaProductTitle.text = [NSString stringWithFormat:#"Product Code:%#",currentProduct.mirsaProductCode];
cell.mirsaProductDescription.text = [NSString stringWithFormat:#"Description: %#",currentProduct.mirsaProductDescription];
[self downloadProductLogoImageView:cell :indexPath.row];
for (int i = 0; i < currentProduct.mirsaProductUrlImage.count; i++) {
[self downloadImageWithCached:currentProduct.mirsaProductUrlImage[i] :cell :indexPath.row :(NSInteger)i];
}
}
else
{
cell.mirsaProductLogoImageView.layer.cornerRadius = 50.0f;
cell.mirsaProductLogoImageView.layer.borderWidth = 1.5f;
cell.mirsaProductLogoImageView.clipsToBounds = YES;
cell.mirsaProductLogoImageView.layer.borderColor = [UIColor colorWithRed:redRedColor green:redGreenColor blue:redBlueColor alpha:ALFA].CGColor;
mirsaProduct *currentProduct = [self.listOfProducts objectAtIndex:indexPath.row];
cell.mirsaProductTitle.text = [NSString stringWithFormat:#"Product Code:%#",currentProduct.mirsaProductCode];
cell.mirsaProductDescription.text = [NSString stringWithFormat:#"Description: %#",currentProduct.mirsaProductDescription];
[self downloadProductLogoImageView:cell :indexPath.row];
for (int i = 0; i < currentProduct.mirsaProductUrlImage.count; i++) {
[self downloadImageWithCached:currentProduct.mirsaProductUrlImage[i] :cell :indexPath.row :(NSInteger)i];
}
}
return cell;
}
-(void)downloadProductLogoImageView:(mirsaProductTableViewCell *)cell :(NSInteger )index;
{
#autoreleasepool {
[cell.mirsaProductActivityIndicatorView startAnimating];
mirsaProduct *currentProduct = [self.listOfProducts objectAtIndex:index];
NSString *cachedKey = currentProduct.mirsaProductImage;
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:#"productLogoImageView"];
[imageCache queryDiskCacheForKey:cachedKey done:^(UIImage *image, SDImageCacheType cacheType)
{
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
[cell.mirsaProductActivityIndicatorView stopAnimating];
cell.mirsaProductLogoImageView.image = image;
});
}else{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = [NSURL URLWithString:currentProduct.mirsaProductImage];
[[SDWebImageDownloader sharedDownloader]downloadImageWithURL:url options:SDWebImageDownloaderLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {
} completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (finished && image){
dispatch_async(dispatch_get_main_queue(), ^{
[imageCache setMaxCacheAge:60*60*24];
[imageCache storeImage:image
recalculateFromImage:NO
imageData:data
forKey:currentProduct.mirsaProductImage
toDisk:YES];
});
[cell.mirsaProductActivityIndicatorView stopAnimating];
cell.mirsaProductLogoImageView.image = image;
}
}];
});
}
}];
}
}
some links that i found on stack overflow Tableview images chaging when scrolling using custom tableview, Incorrect cell data display when scrolling UITableView
Hi as far i go through your code there two major changes that need to be done to solve your problem
if (cell == nil) {
cell = [[mirsaProductTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] ;
cell.mirsaProductLogoImageView.layer.cornerRadius = 50.0f;
in this lines of code don't use nil instead of use cell Identifier
to download image you don't need to write that much of code just write
[imageView sd_setImageWithURL:[NSURL URLWithString:#"http://www.example.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
A third party library like SDWebImage is a reasonable idea, though a simple home-rolled version is not too tough to create. Instead of a regular image view in the cell, use your own subclass, something like this:
// .h
#import <UIKit/UIKit.h>
#interface AsynchImageView : UIImageView
- (void)setImageFromUrl:(NSString *)url placeholder:(UIImage *)placeholder;
#end
// .m
#import "AsynchImageView.h"
#implementation AsynchImageView
- (void)setImageFromUrl:(NSString *)url placeholder:(UIImage *)placeholder {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLCache *cache = [NSURLCache sharedURLCache];
NSCachedURLResponse *cachedResponse = [cache cachedResponseForRequest:request];
if (cachedResponse) {
[self setImageFromData:cachedResponse.data];
} else {
self.image = placeholder;
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
[cache storeCachedResponse:[[NSCachedURLResponse alloc] initWithResponse:response data:data] forRequest:request];
[self setImageFromData:data];
}
}] resume];
}
}
- (void)setImageFromData:(NSData *)data {
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
self.image = image;
});
}
#end
This checks to see if the image has been downloaded already, if it hasn't it sets a placeholder image and starts a download. Upon completion, it sets the image to the downloaded one and caches it.
Remove all of the other image code when configuring the cell, and do this:
NSString *url = currentProduct.mirsaProductImage;
[cell.mirsaProductLogoImageView setImageFromUrl: placeholder:];
I'm trying to make a module for react-native using NYTPhotoViewer and asynchronous image downloading. It works, but first image never stops to animate loading when the other downloads and shows. Interesting, that if I swipe some images (2 and more), the first image will render. The code is here:
#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import "NYTImageViewer.h"
#import "NYTExamplePhoto.h"
#interface NYTImageViewer () <NYTPhotosViewControllerDelegate>
#property (nonatomic) NSArray *photos;
#end
#implementation NYTImageViewer
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(open:(NSArray *)urls)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *photos = addPhotos(urls);
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos];
UIViewController *ctrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[ctrl presentViewController:photosViewController animated:TRUE completion: nil];
});
}
NSArray* addPhotos(NSArray *urls) {
NSMutableArray *photos = [NSMutableArray array];
for (int i = 0; i < [urls count]; i++) {
NYTExamplePhoto *photo = [[NYTExamplePhoto alloc] init];
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: urls[i]]];
if ( imageData == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
photo.image = [UIImage imageWithData: imageData];
});
});
[photos addObject:photo];
}
return photos;
}
#end
How can I fix it?
You shouldn't/can't load that way from a remote URL, and with the dispatch_async it's generating the expected behavior:
NSData * _data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: urls[i]]];
You must use NSURLSession or NSURLConnection via asynchronous method for remote calls, and you'll have to handle recursion at the callback.
I have a UItableView that is listing number of outlets respectively, each outlet has a logo image. I save those images locally on iPhone, so if any image is found on iPhone it will fetch from there if not then it will send a service call and fetch data. It is working accordingly but when I scroll down on tableview it gets hanged at certain point when the image is being downloaded, as it is downloaded it works fine again. Is there any solution where I can perform this multitasking of downloading images along with representing them either from service call or fetching it locally.
Here is my code..
// downloading images of outlets locally
NSLog(#"Downloading...");
NSString *imageLink = [NSString stringWithFormat:#"http://cf.abc.pk/outlets/l/%#",outs.logo];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageLink]]];
NSLog(#"%f,%f",image.size.width,image.size.height);
NSString *docDir =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(#"%#",docDir);
NSLog(#"saving png");
NSString *pngFilePath = [NSString stringWithFormat:#"%#/%d.png",docDir,[[arrOutletIds objectAtIndex:webserviceCall] intValue]];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:pngFilePath];
if(!fileExists)
{
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:YES];
}
Let's try:
//When you download something, execute in background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
//download some thing
dispatch_async( dispatch_get_main_queue(), ^{
// when download finish execute in main thread to update data
// this function should be called in response of downloading
});
});
Hope this helps you.
Download image in background will solve your problem here
Try this.
if(!fileExists)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:YES];
});
}
You can use this code which integrates ImageCache to download async and cache images. This part of code shows downloading images in UITableView. Or you can check out this project on GitHub SDImageCache
if ([[ImageCache sharedImageCache] DoesExist:photoURL] == true)
{
image = [[ImageCache sharedImageCache] GetImage:photoURL];
cell.imageView.image = image;
}
else
{
cell.imageView.image = [UIImage imageNamed:#"PlaceHolder"];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:photoURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
if (cell.tag == indexPath.section) {
cell.imageView.image = image;
[cell setNeedsLayout];
[[ImageCache sharedImageCache] AddImage:image imageURL:photoURL];
}
});
}
});
}
Import these files to your project
ImageCache.h
#import <Foundation/Foundation.h>
#interface ImageCache : NSObject
#property (nonatomic, retain) NSCache *imgCache;
#pragma mark - Methods
+ (ImageCache*)sharedImageCache;
- (void) AddImage:(UIImage *)image imageURL:(NSString *)imageURL;
- (UIImage*) GetImage:(NSString *)imageURL;
- (BOOL) DoesExist:(NSString *)imageURL;
#end
ImageCache.m
#import "ImageCache.h"
#implementation ImageCache
#synthesize imgCache;
#pragma mark - Methods
static ImageCache* sharedImageCache = nil;
+(ImageCache*)sharedImageCache
{
#synchronized([ImageCache class])
{
if (!sharedImageCache)
sharedImageCache= [[self alloc] init];
return sharedImageCache;
}
return nil;
}
+(id)alloc
{
#synchronized([ImageCache class])
{
NSAssert(sharedImageCache == nil, #"Attempted to allocate a second instance of a singleton.");
sharedImageCache = [super alloc];
return sharedImageCache;
}
return nil;
}
-(id)init
{
self = [super init];
if (self != nil)
{
imgCache = [[NSCache alloc] init];
}
return self;
}
- (void) AddImage:(UIImage *)image imageURL:(NSString *)imageURL
{
if (image==nil) {
}
else
{
[imgCache setObject:image forKey:imageURL];
}
}
- (NSString*) GetImage:(NSString *)imageURL
{
return [imgCache objectForKey:imageURL];
}
- (BOOL) DoesExist:(NSString *)imageURL
{
if ([imgCache objectForKey:imageURL] == nil)
{
return false;
}
return true;
}
#end
Right now, I've just some code which fetches the picture from the URL directly.
ViewController.h
(...)
#property (retain, nonatomic) IBOutlet UIImageView *imageView;
(...)
ViewController.m:
#import Header.h
(...)
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *imageURL = [NSURL URLWithString:#"http://www.visitingdc.com/images/eiffel-tower-picture.jpg"];
NSData *myImageData = [NSData dataWithContentsOfURL:imageURL];
imageView.image = [UIImage imageWithData:myImageData];
}
My goal is to view a picture in a imageView which link is stored in a database. The JSON will send the data from the database as a string:
[
{
"image":"http://www.visitingdc.com/images/eiffel-tower-picture.jpg"
}
]
which will be stored in the variable *image in Header.
Header.h
#interface Header : NSObject {
NSString *image;
}
#property (nonatomic, copy) NSString *image;
- (id)initWithDictionary:(NSDictionary *)dictionary;
+ (NSArray *)findAllRemote;
#end
What do I have to write in the NSURL-code in ViewController.m so it fetches the data from the variable instead of a URL-String?
You can store json response in NSSTring, like
self.image = ;//where you have parsed JSON data
and then use -
NSURL *imageURL = [NSURL URLWithString:self.image];
I am new to iOS development so please bear with me.
I am trying to create a basic photo gallery but ran into a problem.
When I started out with the project I just included all the images in my project.
Now after having a lot more images(400+) I started loading them from a server.
I made an array of images using the following line of code:
[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.testsite.com/testPic.png"]]]
Obviously making the user wait for an array of 400+ images to load from a server is unacceptable.
So my question is if I included one image in my project that said something like "Loading", how could I display that image until the actual image loaded from the server?
I'm making a basic grid-style photo gallery using a table-view and scroll-view. It loads up a few rows of small(thumbnail) images and when you click one it makes it full screen.
I'm using Xcode 4.3, ARC, and storyboards if that helps!
Sorry if this is confusing!
-Shredder2794
The simplest way of doing this is to use AFNetworking, which provides setImageWithURL:placeholderImage: in a category on UIImageView (also a method with success/failure handlers).
A method is to subclass UIImageView. When you allocate it you put a default image ( the loading one) or a UIActivityIndicator, download the image you want to display ( in a separate thread) and when the image is downloaded display it. Have a look to NSURLRequest and NSURLConnection for the image download.
* EDIT *
Here is an example of code I developed. You can use this as a start point to develop your own loading image class. This class can be improved by using NSThread for the image loading.
// ImageLoader.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
/**
* #brief Class that loads an UIImage from a server
* #author Nicolas
*/
#interface ImageLoader : UIView
{
#private
NSURLConnection *connection;
NSMutableData *data;
NSString *path;
UIActivityIndicatorView *loading;
UIImageView *imageView;
}
#property (nonatomic, retain) UIActivityIndicatorView *loading;
#property (nonatomic, retain) NSURLConnection *connection;
#property (nonatomic, retain) NSMutableData *data;
#property (nonatomic, retain) NSString *path;
#property (nonatomic, retain) UIImageView *imageView;
/**
* Load an image from a server an display it
* #param URL URL to get the image
* #param chemin path to save the image
* #author Nicolas
*/
- (void)loadImageFromUrl:(NSString *)URL forPath:(NSString *)chemin;
#end
// ImageLoader.m
#import "ImageLoader.h"
#implementation ImageLoader
#synthesize path, connection, data, loading, imageView;
- (id)init
{
self = [super init];
[self setUserInteractionEnabled:YES];
return self;
}
- (void)loadImageFromUrl:(NSString *)URL forPath:(NSString *)chemin
{
//if (connection != nil) [connection release];
//if (data != nil) [data release];
//if (path != nil) [path release];
self.path = chemin;
if ([[NSFileManager defaultManager] fileExistsAtPath:chemin])
{
if (imageView != nil)
{
[imageView removeFromSuperview];
[imageView release];
}
imageView = [[UIImageView alloc] initWithFrame:self.bounds];
imageView.image = [UIImage imageWithContentsOfFile:chemin];
[self addSubview:imageView];
}
else
{
loading = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
loading.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
[loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[loading startAnimating];
[self addSubview:loading];
NSURL *myURL = [NSURL URLWithString:[URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:myURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0f];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
}
#pragma mark -
#pragma mark NSURLConnection protocol
- (void)connection:(NSURLConnection *)_connection didReceiveData:(NSData *)_data
{
if (data == nil)
{
data = [[NSMutableData alloc] initWithCapacity:2048];
}
[data appendData:_data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)_connection
{
[data writeToFile:self.path atomically:YES];
if (imageView != nil)
{
[imageView removeFromSuperview];
[imageView release];
}
imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]];
imageView.frame = self.bounds;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[loading stopAnimating];
[loading setHidden:YES];
[self addSubview:imageView];
}
- (void)connection:(NSURLConnection *)_connection didFailWithError:(NSError *)error
{
[loading stopAnimating];
[loading release];
}
#pragma mark - Memory management
- (void)dealloc
{
[connection cancel];
[connection release];
[imageView release];
[path release];
[data release];
[super dealloc];
}
#end