简体   繁体   English

iOS通用应用程序-为iPad和iPhone访问不同的笔尖

[英]iOS Universal App - Access different Nibs for iPad and iPhone

I am writing my first universal app, I have converted my nibs so that there are iPad and iPhone versions. 我正在写我的第一个通用应用程序,我转换了笔尖,以便有iPad和iPhone版本。

The iPad version is in the Resources-iPad folder and called 'InfoViewController-iPad.xib'. iPad版本位于Resources-iPad文件夹中,名为“ InfoViewController-iPad.xib”。 The iPhone version in the main folder and called 'InfoViewController.xib' 主文件夹中的iPhone版本,名为“ InfoViewController.xib”

I have the following action to show the relevant xib 我有以下动作来展示相关的xib

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
         infoViewController = [[InfoViewController alloc] initWithNibName:@"Resources-iPad/InfoViewController-iPad" bundle:nil];
    }
    else
    {
        infoViewController = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
    }

    infoViewController.delegate = self;
    infoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentModalViewController:infoViewController animated:YES];

    [infoViewController release];

}

When this runs on the iPhone it works fine, but it crashes when run on the iPad. 在iPhone上运行时,它可以正常工作,但在iPad上运行时,它会崩溃。 Any help would really be appreciared 任何帮助都将不胜感激

You do not need to put the folder name in the nib name for the iPad version, it will be found as long as it has a different name than the iPhone version. 您无需将文件夹名称放在iPad版本的笔尖名称中,只要它具有与iPhone版本不同的名称,就可以找到该文件夹​​名称。

If removing the folder from the initWithNibName doesn't work for you, please edit your question and post the results of the backtrace from the console. 如果从initWithNibName中删除文件夹对您不起作用,请编辑您的问题,并从控制台发布回溯结果。

You should not need the Resources-iPad/ prefix on the name of the iPad nib. iPad笔尖的名称上不需要Resources-iPad/前缀。 iOS knows how to find resources in your bundle. iOS知道如何在捆绑软件中查找资源。 The folder hierarchy you see in Xcode is simply for organizing files and for the developer's benefit. 您在Xcode中看到的文件夹层次结构仅用于组织文件并为开发人员带来好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM