UIImage - should be loaded with [UIImage imageNamed:@""] or not ?
- by sagar
Hello ! every one.
I am having number of images with in my application. ( images more than 50 - approximately & it can extend according to client's need )
Each image are very large round about - 1024 x 768 & 150 dpi
Now, I have to add all this images in a scroll view & display it.
Ok, My question is as follows.
According to me there are two options of loading large images
imageNamed:@""
load asynchronously when viewDidLoad Called.
Which is more preferable ?
imgModel.image=[UIImage imageNamed:[dMain valueForKey:@"imgVal"]];
or like this.
NSURL *ur=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:lblModelName.text ofType:@"png"] isDirectory:NO];
NSURLRequest *req=[NSURLRequest requestWithURL:ur cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:40];
[ur release];
NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self];
if(con){
myWebData=[[NSMutableData data] retain];
} else {
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[myWebData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myWebData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"ImageView Ref From - %@",imgV);
// my image view & set image
imgV.image=[UIImage imageWithData:myWebData];
[connection release]; connection=nil;
}