2013-06-06 39 views
0

我需要知道如何在iPhone SDK中打開圖庫。我相信我的代碼是正確的,但我仍然得到一個例外。如何打開iPhone上的圖庫以選擇圖像?

這是我的代碼:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
     imgpkrController.delegate = self; 
     imgpkrController.allowsEditing = YES; 
     imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES]; 

     [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];} 

通過使用此代碼我得到異常:

UIApplicationInvalidInterfaceOrientation', reason: 
    preferredInterfaceOrientationForPresentation must return a supported interface orientation! 

所以,我想這個代碼:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
     UIInterfaceOrientation interface = [[UIApplication sharedApplication] statusBarOrientation]; 
     if(interface == UIDeviceOrientationPortrait) 
     { 
      imgpkrController.delegate = self; 
      imgpkrController.allowsEditing = YES; 
      imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES]; 

      [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil]; 

     }else if (interface ==UIDeviceOrientationLandscapeLeft || interface ==UIDeviceOrientationLandscapeRight) 
     { 
      imgpkrController.delegate = self; 
      imgpkrController.allowsEditing = YES; 
      imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES]; 
      [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];}} 

但是這給同樣的例外。有人能幫我解決這個問題嗎?

回答

0

我不認爲你之前使用的代碼有任何問題。繼續爲此使用該代碼。我認爲UIInterfaceOrientation中的代碼存在問題。你可以試試這個轉到Target-> Summery - >,然後嘗試從那裏處理方向。

如果不那麼幫你需要學習有關UIInterfaceOrientation在以下鏈接

http://www.scott-sherwood.com/ios-6-uiapplicationinvalidinterfaceorientation-exception/

+0

ANKIT我試圖做你的方式告訴,但cudnt能夠取得成功。有沒有人能幫我解決這個問題。 –

+0

imgpkrController應該已經被定義爲一個視圖控制器,爲什麼你在當前的模型視圖控制器中添加imgpkrController就像(UIViewController *)imgpkrController。 – 2013-06-06 10:04:36

+0

因爲這是我知道的唯一方法。如果還有其他方法可以做到這一點,請與我分享。此代碼在其他項目上完美工作,但不在此項目上。 –

相關問題