I have bunch of 'item' objects that include a picture of the item. When my app runs it loads the image of the item from a url. When it is loaded it posts a notification to NSNotificationCenter with the ID of the image.
I have a subclass of UIImageView that has a pointer to the item and listens for notifications with that item ID. When the item's image is loaded from the url the imageView updates the image to the item's image.
However, sometimes (but not 100% of the time) something weird happens and I get an exception thrown:
-[__NSCFType imageLoaded:]: unrecognized selector sent to instance
I think ARC is for some reason releasing an object too early. But I don't use weak pointers because I had a bad experience once. Here is some code:
//Inside my Item object
-(void)loadItemImage{
ConnectionManager *conman = [[ConnectionManager alloc] init];
[conman getImageWithURL:self.imageURL inBackgroundWithBlock:^(NSString *error, id image) {
if (image){
self.image = image;
[[NSNotificationCenter defaultCenter] postNotificationName:[NSString stringWithFormat:@"image%i", self.pk] object:nil]; //exception is thrown here.
}else{
NSLog(@"error: %@", error);
}
}];
}
//inside my ImageView class (subclass of UIImageView)
-(void)imageLoaded:(id)sender{
self.image = item.image;
}
What doesn't make sense to me is that if the object was somehow released wouldn't it then not be listening for the notification? It seems that if the object is listening for a notification then it could call the selector method.