2012-09-06 56 views
0

可能重複:
UIPopover for iphone 4.0相機庫問題

我在Xcode中通用的應用程序。如果用戶正在使用iPad,則來自庫按鈕的使用圖像效果很好。但是,如果他們使用iPhone的按鈕不起作用。

這是我收到的錯誤。

由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:' - [UIPopoverController initWithContentViewController:]在UIUserInterfaceIdiomPad下未運行時調用。

請幫忙!

這是我的代碼。

- (IBAction) useCameraRoll: (id)sender 
{ 

if ([self.popoverController isPopoverVisible]) { 
[self.popoverController dismissPopoverAnimated:YES]; 

} else { 
if ([UIImagePickerController isSourceTypeAvailable: 
    UIImagePickerControllerSourceTypeSavedPhotosAlbum]) 
{ 
    UIImagePickerController *imagePicker = 
    [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 
    imagePicker.sourceType = 
    UIImagePickerControllerSourceTypePhotoLibrary; 
    imagePicker.mediaTypes = [NSArray arrayWithObjects: 
           (NSString *) kUTTypeImage, 
           nil]; 
    imagePicker.allowsEditing = YES; 

    newMedia = NO; 
} 
} 
} 

如何合併下面的代碼? 如果(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad){這裏添加酥料餅的代碼}其他{
添加替代的酥料餅這裏}

回答

0

原因崩潰是UIPopoverController僅適用於iPad的,在IPhone運行時,你不能用它。所以你需要尋找替代品。

+0

試試這個答案,如果你想在iPhone中做出非常類似於UiPopoverController的東西http://stackoverflow.com/a/4124016/1451709 –

+0

有沒有辦法讓它保留在iPad上並將其移除給iPhone? –

+0

是的,你可以實現它。只需檢查應用程序是否在Iphone或Ipad上運行。下面的代碼使用if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) { 添加酥料餅的代碼在這裏 } 其他 { 添加替代的酥料餅這裏 } –