嘿,伙计们,我有以下问题:我有一个IPad应用程序,现在我希望它也能在IPhone上运行。(我知道应该是相反的,但我不能改变它)。因此,现在我想通过使用以下命令来决定我需要哪个视图:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iOS 3.2 or later.
}
else {
// The device is an iPhone or iPod touch.
}这对于除RootViewController之外的所有视图都很有效。
无论我在哪里设置RootViewController的xib,它总是显示我为IPad-App定义的xib。
这是我在App-Delegate中的代码:
viewController = [VoycerUniversalAppViewController sharedInstance];
UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window addSubview:myNavigationController.view];
//[self.window addSubview:self.vcSplashScreen.view];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES; 这是我的VoycerUniversalAppViewController sharedInstance中的代码
+ (VoycerUniversalAppViewController*) sharedInstance
{
@synchronized(self)
{
if(sharedInstance == nil)
{
// only allocate here - assignment is done in the alloc method
if (![AppState sharedInstance].loggedIn)
{
[AppState sharedInstance ].loggedIn = FALSE;
}
}
}
return sharedInstance;
}
+ (id) allocWithZone:(NSZone*)zone {
@synchronized(self) {
if(sharedInstance == nil) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iOS 3.2 or later.
NSLog(@"The device is an iPad running iOS 3.2 or later.");
sharedInstance = [[super allocWithZone:zone] initWithNibName:@"VoycerUniversalAppViewController" bundle:nil];
}
else {
// The device is an iPhone or iPod touch.
NSLog(@"The device is an iPhone or iPod touch.");
sharedInstance = [[super allocWithZone:zone] initWithNibName:@"VoycerUniversalAppIPhoneViewController" bundle:nil];
}
// allocate and assign instance variable on first allocation
return sharedInstance;
}
}
return nil;
}我几乎到处寻找,如果我错过了一些设置或东西,但我找不到任何东西。
你们谁有主意,为什么总是加载VoycerUnversalAppViewController而不是另一个?
两个Xibs都链接到同一个类。
如果解决方案很简单,请不要责怪我,我对xcode、IB和objective-c都是新手(我用objective-c编写代码已经有一个半月了)。
提前进行Thx检查。
Maverick1st。
发布于 2011-01-18 01:39:18
对于主NIB,在info.plist文件中有以下设置:NSMainNibFile和NSMainNibFile~ipad。
在NIB文件中,您可以创建应用程序委托并设置导航控制器。
https://stackoverflow.com/questions/4716037
复制相似问题