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];}}
但是這給同樣的例外。有人能幫我解決這個問題嗎?
ANKIT我試圖做你的方式告訴,但cudnt能夠取得成功。有沒有人能幫我解決這個問題。 –
imgpkrController應該已經被定義爲一個視圖控制器,爲什麼你在當前的模型視圖控制器中添加imgpkrController就像(UIViewController *)imgpkrController。 – 2013-06-06 10:04:36
因爲這是我知道的唯一方法。如果還有其他方法可以做到這一點,請與我分享。此代碼在其他項目上完美工作,但不在此項目上。 –