首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据运行应用程序的设备,从不同的xibs初始化rootViewController

根据运行应用程序的设备,从不同的xibs初始化rootViewController
EN

Stack Overflow用户
提问于 2011-01-18 01:33:41
回答 1查看 647关注 0票数 0

嘿,伙计们,我有以下问题:我有一个IPad应用程序,现在我希望它也能在IPhone上运行。(我知道应该是相反的,但我不能改变它)。因此,现在我想通过使用以下命令来决定我需要哪个视图:

代码语言:javascript
复制
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中的代码:

代码语言:javascript
复制
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中的代码

代码语言:javascript
复制
+ (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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-18 01:39:18

对于主NIB,在info.plist文件中有以下设置:NSMainNibFileNSMainNibFile~ipad

在NIB文件中,您可以创建应用程序委托并设置导航控制器。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4716037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档