UIImagePicker在iPhone和iPad上的顯示方式必須不同。在iPad上,它拋出一個異常,說這句話的:針對iPhone和iPad的條件編碼如何在現實中工作?
'在iPad上,的UIImagePickerController必須 可以通過UIPopoverController呈現'*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,理由是:
所以我必須添加代碼到我的通用應用程序,這是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,我需要保持它的一個實例變量。我將如何處理?
中的UIDevice頭中的'UI_USER_INTERFACE_IDIOM'宏可能是一個更合適的測試。 – Jonah 2011-05-24 16:49:08
這更直接點: if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) – Paulo 2013-09-24 08:28:24