Iphone UIImageView切换setContentMode随机执行错误访问
我在UIViewController中使用UIImageView和UIScrollView来显示图像。工具栏上提供的“实际大小”和“适合屏幕”选项,允许用户在模式之间切换。在模式之间切换时,我随机出现EXEC\u BAD\u访问错误。随机意味着我可以切换到实际大小模式,以适应不同时间的屏幕模式。当我随机点击其中一个时,应用程序崩溃 这是我正在使用的代码,如果它不起作用,我可以发布h和m文件Iphone UIImageView切换setContentMode随机执行错误访问,iphone,uiimageview,Iphone,Uiimageview,我在UIViewController中使用UIImageView和UIScrollView来显示图像。工具栏上提供的“实际大小”和“适合屏幕”选项,允许用户在模式之间切换。在模式之间切换时,我随机出现EXEC\u BAD\u访问错误。随机意味着我可以切换到实际大小模式,以适应不同时间的屏幕模式。当我随机点击其中一个时,应用程序崩溃 这是我正在使用的代码,如果它不起作用,我可以发布h和m文件 -(void)loadImage{ NSString *documentsDi
-(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];
}
谢谢您的帮助。第一个快速猜测是您可能没有保留imageView或其图像?如果你可以发布你的堆栈跟踪,也许是它崩溃的那一行,这将是非常有用的
Program received signal: “EXC_BAD_ACCESS”.