UITabBarControllerに関するAppleのドキュメントから:
このクラスはサブクラス化を目的としていません。代わりに、そのインスタンスをそのまま使用して、ユーザーがさまざまな操作モードから選択できるインターフェイスを提示します
サブクラス化することはできません。元のUITabBarControllerに必要な機能がない場合、唯一の選択肢は、元のタブバーコントローラーをサブクラス化せずに新しいカスタムタブバーコントローラーを作成することです。
編集:あなたがこれをしたいかどうかわからない。ペン先からUITabBarControllerをロードしようとしているだけですか?その場合、サブクラス化は必要ありません。ストーリーボードを使用する方が良いでしょう;-)しかし、ペン先でもそれを行うことができます。あなたは単にこれをしなければなりません:
1-プロジェクトに空のxibを追加し、それをTabBarと呼びます(xibのみ。ソースファイルはありません)
2-そのペン先内にUITabBarControllerを配置します。他のコンポーネントはなく、そのUITabBarControllerのみ
3-このコードをAppDelegateアプリケーションのdidFinishLaunchingWithOptionsメソッドに配置します。
// this code should be already in that method if you have used the empty application model
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// this is the new code to add. You are programmatically loading an instance of UITabBarController from the nib named TabBar.xib
UITabBarController *tb = (UITabBarController *)[[[NSBundle mainBundle]loadNibNamed:@"TabBar" owner:self options:nil] objectAtIndex:0];
// here you are assigning the tb as the root viewcontroller
self.window.rootViewController = tb;
// this code is standard in this method
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
次に、UITabBarControllerをカスタマイズすると、正しく読み込まれるはずです。注意:ペン先内に他のオブジェクトを追加する場合は、線を変更する必要があります
UITabBarController *tb = (UITabBarController *)[[[NSBundle mainBundle]loadNibNamed:@"TabBar" owner:self options:nil] objectAtIndex:0];
ループと、他のコンポーネントではなくUITabBarControllerを実際にロードしているかどうかを確認するためのチェックを行います。これで、UITabBarControllerかUIPotatoかを気にせずに、nibの最初のオブジェクトをロードするだけです;-)