开发者

UIImageView switching setContentMode random EXEC_BAD_ACCESS

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 mod开发者_高级运维e 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.


A first quick guess is that maybe you aren't retaining the imageView or its image? If you could post your stack trace and maybe the line where it crashes, it would be useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜