2015-01-25 2 views
1

xcode 6에서 새 앱을 만들었으므로 더 이상 추위가 없습니다. iOS 8부터는 액션 시트를 표시하기 위해 UIalertcontroller를 사용합니다.Ios uialertcontroller uiimagepicker dismiss : 앱 충돌

사진 라이브러리를 lauch하고 사진을 선택하는 데 사용하지만 피커를 닫으려고 할 때 내 앱이 다운되고 그 이유를 모르겠습니다. 내 코드 아래에 : UIImagePickerController * picker = [[UIImagePickerController alloc] init]; picker.delegate = 자기; picker.allowsEditing = YES; imagepicker 기능 아래

UIAlertController * uiViewActionSheet= [UIAlertController 
          alertControllerWithTitle:@"Action" 
          message:nil 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

UIAlertAction* chooseExisting = [UIAlertAction 
          actionWithTitle:NSLocalizedString(@"CHOOSE_EXISTING",@"Choose Existing") 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction * action) 
          { 
           //Do some thing here 
           picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

           [self presentViewController:picker animated:YES completion:NULL]; 

           [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil]; 

          }]; 

UIAlertAction* cancel = [UIAlertAction 
         actionWithTitle:@"Cancel" 
         style:UIAlertActionStyleCancel 
         handler:^(UIAlertAction * action) 
         { 
          [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil]; 
         }]; 

[uiViewActionSheet addAction:chooseExisting]; 
[uiViewActionSheet addAction:cancel]; 
[self presentViewController:uiViewActionSheet animated:YES completion:nil];  

: 여기

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
self.uImageProfile.image = chosenImage; 
self.lstatutImage.text = @"save"; 
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

if(picker.sourceType == UIImagePickerControllerSourceTypeCamera) 
{ 
    UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil); 
} 

__block NSString* resultSaveImage = @""; 
//Save image onthe server 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

    resultSaveImage = [controllerObject saveProfileImage:self.uImageProfile.image]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 

     if(![resultSaveImage isEqualToString:@"\"ok\""]) 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"Error") message:resultSaveImage delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
      [alert show]; 
     } 
    }); 
}); 

} 

내 코드 충돌 :

[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

하면 어떤 생각이 있나요?

+0

시뮬레이터를 재부팅하면 작동합니다. :) (1 시간 분실 됨 ...) – Jerem

답변

0

그런 다음 picker을 기각하고있는 것은 전화 :

[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

if(picker.sourceType == UIImagePickerControllerSourceTypeCamera) {... 

당신은 또한 [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil]; 라인이 필요하지 않습니다!

종료 줄을 끝까지 이동해보십시오. 그래도 충돌이 발생하면 presentingViewController가 더 이상 작동하지 않을 수 있습니다.