Adding an observer to UIImageView? observer & notifications
Posted
by sagar
on Stack Overflow
See other posts from Stack Overflow
or by sagar
Published on 2010-04-30T06:42:08Z
Indexed on
2010/04/30
6:47 UTC
Read the original article
Hit count: 468
Each class has almost one method named addObserver
[imgVURL addObserver:<#(NSObject *)observer#> forKeyPath:<#(NSString *)keyPath#> options:<#(NSKeyValueObservingOptions)options#> context:<#(void *)context#>]
Here, imgVURL is an image which is going to be load an image asynchronously. When image will be loaded dynamically - other class will set an image from loaded data.
- Now, my question is how can we add an observer to UIImageView's instance.
- Observer and notifications are same or not ?
- If it is not then what's different ?
Let's have some sample code That I did in my project to understand my question.
// locating image view from Scroll view by it's tag
imgVURL=(UIImageView*)[scrMain viewWithTag:(kTagImagesTag+i)];
// ImageViewURL is a class which contains methods of
// didReceiveResponse
// didReceiveData
// connection
ImageViewURL *tmp=[[ImageViewURL alloc] init];
// it has a nonatomic property which will take the reference of my image view
tmp.imgV=imgVURL;
// now I will pass a url from my an array to property strURL
// in strUrl I have custom setter
// in which I am initializing a connection
tmp.strUrl=[NSURL URLWithString:[[tblmain objectAtIndex:i] valueForKey:@"url"]];
// from ImageViewURL.m file
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// NSLog@"ImageView Ref From - %@",imgV);
// see imgV has reference of my -> imgVURL (nonatomic,assign)
imgV.image=[UIImage imageWithData:myWebData];
[connection release]; connection=nil;
}
// as you can see in above code many many images are loaded asynchronously
// now How can I add an observer to an imageview whether it received or not.
© Stack Overflow or respective owner