0

UIImagePicker在iPhone和iPad上的顯示方式必須不同。在iPad上,它拋出一個異常,說這句話的:針對iPhone和iPad的條件編碼如何在現實中工作?

*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,理由是:

'在iPad上,的UIImagePickerController必須 可以通過UIPopoverController呈現'

所以我必須添加代碼到我的通用應用程序,這是iPad的具體。什麼是安全的做法,以便應用程序不會在缺乏UIPopoverController的設備上崩潰?

實施例:

popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
     [popover presentPopoverFromRect:CGRectMake(100, 100.0, 0.0, 0.0) 
           inView:self.view 
       permittedArrowDirections:UIPopoverArrowDirectionAny 
           animated:YES]; 

此外,如果我需要一個UIPopoverController,我需要保持它的一個實例變量。我將如何處理?

回答

3

您可以查看是否通過這樣做存在一個類。

Class popoverClass = (NSClassFromString(@"UIPopoverController")); 
if (popoverClass != nil) { 
// you're on ipad 
} else { 
// you're on iphone/ipod touch 
} 
2

你可以做一個快速檢查其設備的您正與:

[[UIDevice currentDevice] model]; 
+1

中的UIDevice頭中的'UI_USER_INTERFACE_IDIOM'宏可能是一個更合適的測試。 – Jonah 2011-05-24 16:49:08

+0

這更直接點: if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) – Paulo 2013-09-24 08:28:24

相關問題