0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UINavigationController *HomeNav = [[UINavigationController alloc] initWithRootViewController:[[HomeController alloc] init]];

[HomeNav.navigationBar setTintColor:[UIColor clearColor]];

CustomTabBar *tabBar = [[CustomTabBar alloc] init];
tabBar.buttonImages = [NSArray arrayWithObjects:@"t1.png" , nil];
tabBar.hightLightButtonImages = [NSArray arrayWithObjects:@"th1.png",  nil];
tabBar.viewControllers = [NSArray arrayWithObjects:HomeNav , nil];
self.tabBarController = tabBar;
[tabBar release];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

return YES;
}

in HomeController view, there is one button if tap the button I call `AViewController.

-(IBAction)tapButtonA:(id)sender;
{
    [self.navigationController pushViewController:AViewController animated:YES];
}

there is also a button on the view of AViewController.

if I tap the button, I call UIImagePickercontroller

-(IBAction)tapButtonB:(id)sender;
{
 UIImagePickerController *picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsImageEditing = YES;

[self presentModalViewController: picker animated:NO]; 
}

If I tap the cancel button of the UIImagePickerController

-(void)imagePickerControllerDidCancel:(UIImagePickerController*)picker{
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}

the UIImagePicker will dismiss, but after 1,2 seconds the app crashes and displays

enter image description here

Welcome any comment

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
arachide
  • 8,006
  • 18
  • 71
  • 134
  • 2
    Try profiling the app: `+I` -> `Zombies` and see is that's the problem. – tipycalFlow Mar 28 '12 at 06:47
  • check this link : http://stackoverflow.com/questions/8454820/ios-5-uiimagepickercontroller-crash – Devang Mar 28 '12 at 06:51
  • You should delete your image because it isn't informative – Gargo Mar 28 '12 at 06:58
  • @user262325: **What have you tried**? Did you try profiling? Also did you try Analyzing? First you need to refer to : http://www.whathaveyoutred.com – Parth Bhatt Mar 28 '12 at 07:02
  • Also your question title is wrong as it crashes after 1 or 2 seconds the UIImagePickerController is dismissed. So your problem lies somewhere else. – Parth Bhatt Mar 28 '12 at 07:03
  • I use Instrument Zombie to track, when I call UIImagePickerController another time, it says "An Object-C message was sent to a deallocated object(zombie) at address 0x7da9510 responsible call -[UIView _createLayerWithFrame] – arachide Mar 29 '12 at 02:29
  • I notice there is warning on [picker setDelegate:self]; Sending 'BViewController' to parameter of imcompatible type 'id' – arachide Mar 29 '12 at 02:40

3 Answers3

0

Following code is solve your problem,

#pragma mark - UIActionsheet Delegate method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {


                self.imagePicker = [[UIImagePickerController alloc] init];
                self.imagePicker.delegate = self;
                self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                self.imagePicker.allowsEditing = NO;
                self.imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
                [self presentModalViewController:self.imagePicker animated:YES];
            }
            else{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                                message:@"Unable to connect camera." 
                                                               delegate:self cancelButtonTitle:@"Ok" 
                                                      otherButtonTitles:nil];
                [alert show];
            }
            break;
        case 1:

            self.imagePicker = [[UIImagePickerController alloc] init];
            self.imagePicker.delegate = self;
            self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
            [self presentModalViewController:self.imagePicker animated:YES];


            break;
        default:
            break;
    }
}




#pragma mark - UIImagePicker Delegate method
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];


   self.imgForEvent=image;

    //    // Save image
    //     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    //         UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    //     }
    [self dismissModalViewControllerAnimated:YES];

}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;

    // Unable to save the image  
    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    else // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    [alert show];

    [self.imagePicker dismissModalViewControllerAnimated:YES];

}

This code may helping to solveing your problem

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
  • I use Instruments Zombie to track, when I call UIImagePickerController another time, it says "An Object-C message was sent to a deallocated object(zombie) at address 0x7da9510 -[UIView _createLayerWithFrame] – arachide Mar 29 '12 at 02:30
  • I notice there is warning on [picker setDelegate:self]; Sending 'BViewController' to parameter of imcompatible type 'id' – arachide Mar 29 '12 at 02:40
0

I think you want:

-(void) imagePickerControllerDidCancel:(UIImagePickerController*)picker {
    [picker.presentingViewController dismissModalViewControllerAnimated:YES];
}
zpasternack
  • 17,838
  • 2
  • 63
  • 81
  • I use Instrument Zombie to track, when I call UIImagePickerController another time, it says "An Object-C message was sent to a deallocated object(zombie) at address 0x7da9510 – arachide Mar 29 '12 at 02:30
0

try this

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}
hchouhan02
  • 948
  • 1
  • 8
  • 18
  • I use Instrument Zombie to track, when I call UIImagePickerController another time, it says "An Object-C message was sent to a deallocated object(zombie) at address 0x7da9510 – arachide Mar 29 '12 at 02:30