iphone - newViewController 始终带有两个 Nib (iPhone 和 iPad)

标签 iphone ios objective-c xcode ipad

为通用应用程序 xibs 定制 xcode,这样当我创建一个像 VideoVC 的新 ViewController 时,它必须为此创建两个 nib 文件,

  • 视频VC_iPhone

  • VideoVC_iPad

谁能帮帮我。没有指导方针。只是步骤。谢谢

最佳答案

您将在“/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode”中看到模板文件夹 在这里您将看到文件和项目模板,您可以根据需要编辑或创建新模板。

针对您的问题,导航到此文件夹“/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates”

在这里,您可以通过在带有 Nib 的 View Controller 模板中为 iPad 添加一个空白 Nib 来实现您正在尝试做的事情。我已经上传了一个我做的示例,它仍在进行中,但它会根据您的需要创建 2 个 Nib 。

[my custom template]
http://www.saplogix.net/Xcode_Custom_Template/TwoNibTemplate.zip
extract and copy that inside this folder "~/Library/Developer/Xcode/Templates/File Templates"

Note: create the directory if it's not already there.

待办事项:添加代码以根据设备加载特定 Nib ,这也已完成,只需添加即可。此外,它仅适用于作为父类(super class)的 UIViewController。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    }
    else
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        {
            NSString *_nibBundleOrNil = (NSString *)(nibBundleOrNil != nil ? [nibNameOrNil stringByAppendingString:@"_iPad"] : [NSStringFromClass([self class]) stringByAppendingString:@"_iPad"]);
            self = [super initWithNibName:_nibBundleOrNil bundle:nibBundleOrNil];
        }
    
    if (self)
    {
        // Custom initialization
    }
    return self;
}

我的模板将生成以下条目,您可以使用它来创建具有 2 个 Nib 的 Controller 。 My template will produce the following entry u can use that to create controller with 2 nibs.

关于iphone - newViewController 始终带有两个 Nib (iPhone 和 iPad),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713710/

相关文章:

ios - 设置tableview的动态高度

ios - 如果没有互联网,请更改 ViewController

ios - 调用CSSearchableIndex indexSearchableItems时为BAD_ACCESS

iphone - 子类化 UIButton 添加一个属性

iphone - 为什么我的 UIWebView 中没有应用 CSS?

iphone - 如何在 iPhone 中解析 gdata xml?

ios - 从另一个类访问 UI 操作

ios - JSQ 短信后带有媒体消息

objective-c - NSLayoutConstraint 的默认常量是什么?

ios - 如何将 PDF 作为输入传递给打印机