2011-09-19 6 views
1

아무도이 문제를 해결할 수 있습니까?UIImagePickerController를 사용하고 IOS를 사용하여 IOS를 개발하면 앱이 멈추게됩니다 (크래시가 아님)

마지막 질문에서와 같이, 나는 3 개의 탭 항목과 함께 tabBarController를 사용하고 있습니다. 세 번째 탭에는 카메라 (UIImagePickerController)가있는 uiViewController가 있습니다.

이제 모든 것이 한 가지를 제외하고는 작동합니다. 카메라로 이미지를 촬영하고 "사용"을 누르면 이미지가 저장되었다는 알림이 표시되고 사진 앨범에서 볼 수 있습니다 (앱을 닫고 보았을 때). 그러나이 앱은이 점에 박히지 않습니다. 그리고 나는 더 이상 아무것도 할 수 없다. 화면에서 이미지를 볼 수 있으며 "사용"및 "다시 찍기"버튼을 사용할 수 없습니다. 그냥 그렇게 붙어있어.

내가 여기서 잘못하고있는 것을 볼 수 있습니까?

ps. 모든 예제와 튜토리얼에서 나는 취소의 선택기 릴리스가 있다는 것을 발견했다 ... (또한 내 코드에서). 내 경우 피커 뷰 컨트롤러 (imgPicker) 속성이며 dealloc 메서드에서 언제나처럼 그것을 릴리스, 쓰기 또는 잘못 있습니까? 내가 그 것처럼 살거야, 아니면 여기서 나쁜 기억을하고있는 것일까? (나는 여기서 나쁜 기억 오류를 얻지는 못한다. 그러나 내 실수일지도 모른다. ..)?

viveWillAppear 대리자 메서드에서 UIImagePicker를로드합니다. 당신은 오른쪽에있어,

#pragma mark - 
#pragma mark - UIImagePicker delegate methods 

//saving the image that was taken 
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info 
{ 
    // Access the uncropped image from info dictionary 
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

    // Save image 
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

    [picker release]; 
} 

//alerting the user if the images was saved or not 
- (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]; 
    [alert release]; 
} 

//if user is cancelling the camera 
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
    [self.tabBarController setSelectedIndex:0]; 
} 

가 대단히 감사합니다 Erez

답변

3

: 모든 것은 ... 같은 TakePhotoViewController.m 파일에

-(void) viewWillAppear:(BOOL)animated{ 
    self.imgPicker = [[UIImagePickerController alloc] init]; 
    self.imgPicker.allowsEditing = NO; 
    self.imgPicker.delegate = self; 
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentModalViewController:imgPicker animated:YES]; 
} 

및 위임 방법입니다 취소 액션으로 추적하지만 다른 액션에 대해서는 수행하지 못했습니다.

각 액션 후에 ViewController에서 닫기를 호출해야합니다 엔.

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

편집 : 새로운 링크를 당신이 당신의 위임, YES이 속성을 설정하면 https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/doc/uid/TP40007070

... 그러나, 이 기각해야한다가 사용자 후 이미지 피커 인터페이스는 하나의 사진을 촬영하거나 작업을 취소합니다. 당신이 1 개 이상 사진을 촬영해야하는 경우

그래서, showCameraControls는 NO로 설정해야합니다, 당신은 당신의 자신의 CameraOverlayView를 사용해야합니다.

또한 위임자의 선택기를 출시하지 마세요. ViewController가 뷰를 pop하면, 자동적으로 그것을 해제 할 것이다 (피커가 다른 곳에 유지되지 않는다고 가정). 엄지 손가락의 규칙, 만약 당신이 그것을 소유하지 않는다면 그것을 풀어 내지 마십시오. (이 개념은 아마도 iOS5 ARC가 평범 해지면 잊어 버릴 것입니다.)

ViewController가 제공된 후에는 반드시 해제해야합니다.

iPhone - modalViewController release

편집 :

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info 
{ 
    /* Do what you need to do then */ 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 

//alerting the user if the images was saved or not 
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo 
{ 
    /* Do what you need to do then */ 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 

//if user is cancelling the camera 
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    /* Do what you need to do then */ 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 
+0

대답 해 주셔서 감사합니다,하지만 난 여전히 무엇을 이해하지 : 더 코드

-(void) viewWillAppear:(BOOL)animated{ // No need to store... this is 1 use only anyway. Save memory, and release it when done. UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init]; imgPicker.allowsEditing = NO; imgPicker.delegate = self; imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:imgPicker animated:YES]; [imgPicker release]; // Release this here, this will execute when modal view is popped. } 

위임을 도움이됩니다. didFinishPicking .... 메서드에 동일한 것을 추가하고 동일한 결과를 얻고 있습니다. 그리고 imgPicker에 대한 할당량을 viewDidLoad로 변경 한 다음 하나의 릴리스에 하나의 alloc을 할당합니다 (dealloc에서 release). – Erez

+0

내 prev 코멘트에 신경 쓰지 마라, 당신의 대답은 완벽했다, 고맙다 .-) – Erez

+1

어쨌든 더 많은 코드를 추가했다 :) –

관련 문제