2012-04-10 54 views
1

我在使用操作手冊中的ios攝像頭時遇到了一個尷尬的問題:當用戶觸摸「圖片按鈕」時,操作手冊會顯示兩個選項(要使用照片庫中的照片或用相機拍照)。iPhone攝像頭沒有顯示

無論我選擇什麼選項,什麼都不會發生,但是當我再次選擇媒體類型時,它可以工作。

貝婁是我的代碼:

- (IBAction)selectMediaType: (id)sender { 
    [appDelegate hideTabBar]; 
    UIActionSheet *action = [[UIActionSheet alloc] 
          initWithTitle: nil 
          delegate:self 
          cancelButtonTitle:@"Fechar" 
          destructiveButtonTitle: nil 
          otherButtonTitles:@"Galeria", @"Tirar Foto", nil]; 

    [action showFromTabBar: appDelegate.tabController.tabBar]; 
} 


- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 0) { 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
     NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]; 

     imagePicker.delegate = self; 
     imagePicker.hidesBottomBarWhenPushed = YES; 
     imagePicker.mediaTypes = mediaTypes; 
     imagePicker.allowsEditing = NO; 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

     [self presentModalViewController:imagePicker animated:YES]; 
     imagePicker.hidesBottomBarWhenPushed = YES; 
    } else if (buttonIndex == 1) { 
     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
      NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]; 

      imagePicker.delegate = self; 
      imagePicker.mediaTypes = mediaTypes; 
      imagePicker.allowsEditing = YES; 
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
      imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; 

      [self presentModalViewController:imagePicker animated:YES]; 
     } else { 
      UIAlertView *alert = [[UIAlertView alloc] 
            initWithTitle:@"" 
            message:@"Your device does not support this feature!" 
            delegate:self 
            cancelButtonTitle:@"OK" 
            otherButtonTitles: nil]; 
      [alert show]; 
      [alert release]; 

     } 
    } else { 
     [appDelegate showTabBar]; 
    } 
} 



- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    UIImage *image; 
    NSURL *mediaURL; 

    mediaURL = (NSURL *) [info valueForKey:UIImagePickerControllerMediaURL]; 

    if (mediaURL == nil) { 
     image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage]; 
    } 

    imageView.image = image; 

    [picker dismissModalViewControllerAnimated:YES]; 

    [appDelegate showTabBar]; 
} 

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

    [picker dismissModalViewControllerAnimated:YES]; 

    [appDelegate showTabBar]; 
} 

誰能幫助我?

謝謝。

回答

1

我明白了。

基本上它是一個內存泄漏問題:我在超級視圖中切換視圖添加子視圖(不是在當前視圖中),但我沒有從超級視圖中刪除舊的視圖,所以我得到了內存泄漏;)