One of the views in my app has a method to set it’s ‘default’ layout – setDefaultView. In this method, I loop through the subViews, and if one is an ImageView, it sets the image to nil.
This works fine when my app is initially launched from XCode. But, when I hibernate my app by pressing the home button, then go back into the app and trigger setDefaultView, it crashes in this method where the images are set to nil.
Any suggestions on what may be going wrong here?
Source code:
-(void)setDefaultView {
// Hide all equals labels and images; set all images to nil
for (UIView *view in [secondScrollerView subviews]) {
if ([view isKindOfClass:[UILabel class]]) {
UILabel *label = (UILabel *)view;
if ([label.text isEqualToString:@"="]) {
label.hidden = YES;
}
}
if ([view isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView *)view;
imageView.hidden = YES;
imageView.image = nil; // Crashes here
}
}
// do other stuff here...
}
Most probable is that you set the
imageView.imageto an autoreleased object. TheimageView.image = nil;line will release the old image, which will be a problem if it is already released.