在开发的过程中universal apps
,我们必须conditional code
为每个编写一个device
-iPad
以及iPhone
. 在这种情况下,正确使用tilde
可能是非常有益的。
例如,如果要推送新的视图控制器,则必须编写很多行(几乎 10 行)代码:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_iphone” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
else
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_ipad” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
我们如何区分iphone和ipad的图像?