2012-03-28 3 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

+0

проверить эту ссылку: http://stackoverflow.com/questions/8454820/ios-5-uiimagepickercontroller-crash – Devang

+0

Вы должны удалить свое изображение, потому что оно не является информативным – Gargo

ответ

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

Я использую инструменты Zombie для отслеживания, когда я называю UIImagePickerController другого время, он говорит: «сообщение Объектно-C было отправляется на освобожденный объект (зомби) по адресу 0x7da9510 - [UIView _createLayerWithFrame] – arachide

+0

Я замечаю, что есть предупреждение на [picker setDelegate: self]; Отправка «BViewController» для параметра imcompatible типа «идентификатор » – arachide

+0

вы можете реализовать свой код –

0

Я думаю, что вы хотите:

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

Я использую инструмент зомби, чтобы отслеживать, когда я называю UIImagePickerController другое время, он говорит: «Сообщение Объектно-C был послан к удаленному объекту (зомби) по адресу 0x7da9510 – arachide

0

попробовать этот

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

Я использую Instrument Zombie для отслеживания, когда я вызываю UIImagePickerController в другое время, он говорит: «Сообщение Object-C было отправлено на освобожденный объект (зомби) по адресу 0x7da9510 – arachide

+0

вы использовали мой код? – hchouhan02

Смежные вопросы