[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if(data != nil && self.superview != nil) { // <-- EXC_BAD_ACCESS on this line
[self.musicItemImg setAlpha:0.0];
[self.musicItemImg setImage:[UIImage imageWithData:data]];
[UIView animateWithDuration:0.25 animations:^{
[self.musicItemImg setAlpha:1.0];
}];
}
});
}];
Sometimes this view is removed before the async load is finished and when it tries to use self
I get an EXC_BAD_ACCESS
and understandably so. Can I abort an async connection? Or is there a better way to combat this?