为通用应用程序 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 。
关于iphone - newViewController 始终带有两个 Nib (iPhone 和 iPad),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713710/