tags:

views:

45

answers:

1

i have created a project which has different xib viewcontrollers.In first view am selecting an image through picker controller and am displaying it in the secondviewcontroller.In secondview controller i have some buttons and i have given some IBActions to them.Here starts my problem that am successfully displaying the image in secondviewcontorller but when i tap on button in that viewcontroller app is terminating and the debugger showing the error message as program terminated due to uncaught exception

Here is the code:

To select the pic through pickercontroller in first view

-(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];
    }

}

displaying in the second view and assigning the actions .h file

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

.m file

@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];
    }

}

I dont know whats wrong with my code please help me.I have given appropriate connections in IB.. Thanks in Advance

A: 

For some UIKit class, his delegate has some methods which must be implemented. For example, UIImagePickerViewControllerDelegate must implement following methods:

  • – imagePickerController:didFinishPickingMediaWithInfo:
  • – imagePickerControllerDidCancel:

For your above codes, I don't know whether these methods are implemented or not. Hope these information can help you.

Toro