IBActions不在另一个viewcontroller中工作

时间:2010-10-07 10:05:04

标签: iphone xcode

我已经创建了一个具有不同xib viewcontrollers的项目。在第一个视图中我通过选择器控制器选择一个图像并在secondviewcontroller中显示它。在第二个视图控制器中我有一些按钮,我给了他们一些IBActions。这里开始我的问题是在secondviewcontorller中成功显示图像但当我点击该viewcontroller应用程序中的按钮时终止并且调试器显示错误消息程序因未捕获的异常而终止

以下是代码:

在第一个视图中选择pic到pickercontroller

-(IBAction)btnChoosePicClicked {
    if([UIImagePickerController         isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker=[[UIImagePickerController alloc] init];
        picker.delegate=self;
        picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;  
        [self presentModalViewController:picker animated:YES];
        [picker release];

    }
    else 
    {
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Error accessing photo library"   message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!"                   otherButtonTitles:nil];

        [alert show];
        [alert release];
    }

}

在第二个视图中显示并分配动作.h文件

@interface editScreen : UIViewController{
    IBOutlet UIButton *btnRotate;
    IBOutlet UIButton *btnLibrary;
    IBOutlet UIImageView *imgView;
    int RotateAngle;
}
-(void)setImage:(UIImage *)img;
-(IBAction)btnLibraryClicked;
-(IBAction)RotateImage;
@end

.m文件

@implementation editScreen
-(void)setImage:(UIImage *)img
{
    [imgView setImage:img];
    imgView.userInteractionEnabled = YES;
}
-(IBAction)RotateImage
{
    CGAffineTransform transform = imgView.transform;
    transform = CGAffineTransformRotate(transform, M_PI/2);
    imgView.transform=transform;

    RotateAngle+=90;

    if(RotateAngle>=360)
    {
        RotateAngle-=360;
    }
    //imageview.transform = CGAffineTransformScale(imageview.transform, -1.0, 1.0);
}
-(IBAction)btnLibraryClicked {


    if([UIImagePickerController                   isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker=[[UIImagePickerController alloc] init];
        picker.delegate=self;
        picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;  
        [self presentModalViewController:picker animated:YES];
        [picker release];
        // NSFileHandle *fileHandle = [[NSFileHandle alloc]initWithFileDescript
    }
    else 
    {
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];

        [alert show];
        [alert release];
    }

}

我不知道我的代码有什么问题请帮助我。我已经在IB中给出了适当的连接.. 在此先感谢

1 个答案:

答案 0 :(得分:0)

对于某些UIKit类,他的委托有一些必须实现的方法。 例如,UIImagePickerViewControllerDelegate必须实现以下方法:

  • - imagePickerController:didFinishPickingMediaWithInfo:
  • - imagePickerControllerDidCancel:

对于您的上述代码,我不知道这些方法是否已实施。希望这些信息可以帮到你。