在AppDelegate里,通过获取UIDevice的userInterfaceIdiom属性,可以检测到当前程序是运行在iphone或者是ipad上,分别加载相应的视图,就能在两种设备中正常的运行起来。 例子如下:
UIDevice* device=[UIDevice currentDevice];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (device.userInterfaceIdiom==UIUserInterfaceIdiomPhon e) {
IPhoneViewController* IPhoneViewController1=[[IPhoneViewController alloc]init];
window.rootViewController= IPhoneViewController1;
[IPhoneViewController1 release];
}
else if (device.userInterfaceIdiom==UIUserInterfaceIdiomPad)
{
IPadViewController* IPadViewController1=[[IPadViewController alloc]init];
window.rootViewController= IPadViewController1;
[IPadViewController1 release];
}