Hi, I'm using an UIImageView and UIScrollView inside UIViewController to show images. Actual Size and Fit to Screen options available at the toolbar to let user switch between modes. While switching between modes I am getting EXEC_BAD_ACCESS error randomly. Randomly means I can switch to Actual Size mode to Fit to Screen modes copule of times. When I hit one of them randomly application crashes.
Here is the code that I am using if it wont help I may post the h and m files.
-(void)loadImage{
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:imgFilePath];
imageView.image = [UIImage imageWithData: [NSData dataWithContentsOfFile:filePath]];
imgLoaded = 1;
}
-(void)FitToScreen{
if(imgLoaded<1) [self loadImage];
if(currentState != STATE_IMGPLAYER_FULLSCREEN ){
currentState = STATE_IMGPLAYER_FULLSCREEN;
//[imageView setContentMode:UIViewContentModeCenter];
[imageView setContentMode:UIViewContentModeScaleToFill];
CGSize photoSize = imageView.frame.size;
[scrollView setContentSize:photoSize];
}
//
}
-(void)ActualSize{
if(currentState != STATE_IMGPLAYER_ACTUAL_SIZE){
currentState = STATE_IMGPLAYER_ACTUAL_SIZE;
[imageView setContentMode:UIViewContentModeTopLeft];
[scrollView setContentMode:UIViewContentModeCenter];
CGSize photoSize = [imageView.image size];
[scrollView setContentSize:photoSize];
}
}
-(IBAction)info_clicked:(id)sender
{
UIButton *button = (UIButton *)sender;
if ([button tag] == BTN_FIT2SIZE) {
[Button setEnabled:NO];
[Button2 setEnabled:YES];
[self ActualSize];
} else if ([button tag] == BTN_FIT2SCREEN) {
[Button setEnabled:YES];
[Button2 setEnabled:NO];
[self FitToScreen];
}
[button release];
}
Console Msg:
Program received signal: “EXC_BAD_ACCESS”.
Thanks for your help.