我需要找到的原因是,在iPad上,UIPickerView在横向方向上具有与在纵向方向相同的高度.在iPhone上它是不同的.iPad编程指南为UIDevice引入了一个"成语"值:
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
// iPad
}
else
{
// iPhone
}
Run Code Online (Sandbox Code Playgroud)
你在iPad(3.2)但不是iPhone(3.1.3)时工作正常 - 所以看起来还需要有一个ifdef来有条件地编译那个支票,比如:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
// etc.
}
#endif
Run Code Online (Sandbox Code Playgroud)
对我而言,开始看起来非常笨拙.什么是更好的方式?
这是检测用户正在运行的设备的正确方法吗?
NSString *currentModel = [[UIDevice currentDevice] model];
if ([currentModel isEqualToString:@"iPhone"]) {
// The user is running on iPhone so allow Call, Camera, etc.
} else {
// The user is running on a different device (iPod / iPad / iPhone Simulator) disallow Call.
}
Run Code Online (Sandbox Code Playgroud)