I have written my code in -(void)loadView{ }
to get an image from internet using NSURL. But before loading image I need to show the spinner( UIActivityIndicatorView
).
#import "ImageFromWebViewController.h"
#define USE_TEST_SERVER 1
@implementation ImageFromWebViewController
+(NSString *)fileName
{
#if USE_TEST_SERVER
return @"http://happyhyderabad.files.wordpress.com/2009/04/anushka4.jpg";
#else
return @"http://nutritionresearchcenter.org/healthnews/wp-content/uploads/2008/07/johnny_depp.jpg";
#endif
}
- (void)loadView {
NSString *urlString = [ImageFromWebViewController fileName];
NSURL *url = [NSURL URLWithString:urlString];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
imageView = [[UIImageView alloc] initWithImage:image];
contentView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setContentSize:[image size]];
[contentView addSubview:imageView];
[imageView setUserInteractionEnabled:NO];
self.view = contentView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[imageView release];
[contentView release];
[super dealloc];
}
@end
In viewDidLoad
I wrote the code for UIActivityIndicatorView
but the spinner started after loading of the image and it is not stopping.
Where should I write the code for the spinner ?