答えのコードは役に立ちましたが、ユニバーサルアプリ(iphone / ipad)に適したものが必要でした。
他の誰かが同じことを必要とする場合に備えて、ここにあなたが始めるための何かがあります。
同じ名前のxibsを持つViewControllerのiOSのnib/xib命名基準を使用してユニバーサルアプリを構築したとします。
名前を指定しない場合にxibsを自動ロードするための2つの組み込みデフォルトは、initWithNibNameに渡されます。
- ExampleViewController.xib[クラシックレイアウトのiphone4/4sなどのRetina3.5フルスクリーンでペン先の名前が空の場合のiphoneのデフォルト...]
- ExampleViewController〜ipad.xib[ペン先が空の場合のipad/ipadminiのデフォルト]
ここで、Retina4フルスクリーンオプションを使用してIBのiphone5 / 5sにカスタムxibsが必要であるとしましょう。つまり、どの568hデバイスでも3.5xibsを表示したくないとします。
カテゴリアプローチを使用したカスタム命名規則は次のとおりです。
- ExampleViewController-568h.xib [Retina 4フルスクリーン(568h)のペン先名が空の場合のiphoneの非デフォルト/カスタム命名規則]
組み込みの名前付けのデフォルトをオーバーライドする代わりに、カテゴリを使用して、コントローラーに適切なxibを設定します。
https://gist.github.com/scottvrosenthal/4945884
ExampleViewController.m
#import "UIViewController+AppCategories.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
nibNameOrNil = [UIViewController nibNamedForDevice:@"ExampleViewController"];
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Do any additional customization
}
return self;
}
UIViewController + AppCategories.h
#import <UIKit/UIKit.h>
@interface UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name;
@end
UIViewController + AppCategories.m
// ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen]
// ExampleViewController-568h.xib [iphone custom naming convention when nib named empty for Retina 4 Full Screen (568h)]
// ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
#import "UIViewController+AppCategories.h"
@implementation UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([UIScreen mainScreen].bounds.size.height == 568)
{
//Check if there's a path extension or not
if (name.pathExtension.length) {
name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@".%@", name.pathExtension] withString: [NSString stringWithFormat:@"-568h.%@", name.pathExtension ]
];
} else {
name = [name stringByAppendingString:@"-568h"];
}
// if 568h nib is found
NSString *nibExists = [[NSBundle mainBundle] pathForResource:name ofType:@"nib"];
if (nibExists) {
return name;
}
}
}
// just default to ios universal app naming convention for xibs
return Nil;
}
@end