2012-03-28 88 views
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; 
} 

HomeController观点,有一个按钮 如果轻按按钮,我称之为'AViewController。的UIImagePickerController导致崩溃的iOS5上

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

AViewController的视图上还有一个按钮。

如果我点击该按钮时,我打电话UIImagePickercontroller

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

[self presentModalViewController: picker animated:NO]; 
} 

如果我点击的UIImagePickerController

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

UIImagePicker将驳回取消按钮,但1,2秒的应用程序崩溃后并显示

enter image description here

欢迎任何评论

+2

尝试剖析应用程序:' + I' - >'Zombies',看看是不是这样的问题。 – tipycalFlow 2012-03-28 06:47:04

+0

检查此链接:http://stackoverflow.com/questions/8454820/ios-5-uiimagepickercontroller-crash – Devang 2012-03-28 06:51:39

+0

你应该删除你的图像,因为它不提供信息 – Gargo 2012-03-28 06:58:58

回答

0

下面的代码是解决你的问题,

#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]; 

} 

此代码可以帮助solveing您的问题

+0

我用Instruments Zombie来跟踪,当我再次调用UIImagePickerController时,它说“一个Object-C消息是发送到解除分配的对象(僵尸)在地址0x7da9510 - [UIView _createLayerWithFrame] – arachide 2012-03-29 02:30:20

+0

我注意到有警告 [picker setDelegate:self]; 发送“BViewController”以不亲类型的参数“ID ” – arachide 2012-03-29 02:40:41

+0

你能实现我的代码 – 2012-03-29 05:30:01

0

我想你想:

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

我使用仪器僵尸进行跟踪,当我打电话的UIImagePickerController另一次,它说“的对象-C消息被发送到地址0x7da9510的一个释放对象(僵尸) – arachide 2012-03-29 02:30:33

0

试试这个

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    [picker dismissModalViewControllerAnimated:YES]; 
} 
+0

我使用Instrument Zombie来跟踪,当我再次调用UIImagePickerController时,它说“一个Object-C消息被发送到地址为0x7da9510的已释放对象(僵尸) – arachide 2012-03-29 02:30:48

+0

您是否使用过我的码? – hchouhan02 2012-03-29 06:14:38