ウィンドウ ベースのアプリ (TabBar と呼びます) を作成します。TabBarAppDelegate では、2 つの UIViewController と 1 つの UITabBarController を作成します。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // アプリケーション起動後のカスタマイズのポイントをオーバーライドします。 UIViewController *vc1 = [[UIViewController 割り当て] initWithNibName:@"MyFirstViewController" bundle:nil]; UIViewController *vc2 = [[UIViewController 割り当て] initWithNibName:@"MySecondViewController" bundle:nil]; NSArray *contr = [NSArray arrayWithObjects:vc1, vc2, nil]; UITabBarController *tbc = [[UITabBarController alloc] init]; tbc.viewControllers = contr; [self.window addSubview:tbc.view]; [self.window makeKeyAndVisible]; [vc1 リリース]; [vc2 リリース]; はいを返します。 }
MyFirstViewController.xib で、uilabel (ビューがロードされていることをテストするために IB を使用) と MySecondViewController.xib も作成します。
アプリのビルドと実行は成功しましたが、uitabbaritem - 画像とタイトルがありません。MyFirstViewController.m にこの行を追加して、MyFirstViewController のタイトルと画像を設定しようとしました
- (id)initWithNibName:(NSString *)nibNameOrNil バンドル:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; もし (自己) { UITabBarItem *item = [[UITabBarItem 割り当て] initWithTitle:@"first" image:[UIImage imageNamed:@"first.png"] tag:0]; self.tabBarItem = アイテム; 【アイテム解放】; } 自分自身を返します。 }
しかし、最初のタブバー項目は変更されていません。お願い助けて。私が間違っていることを理解していません。