質問

私はナビゲーションコントローラベースのアプリケーションを持っていました。そして、私は自分のアプリケーションでは、タブ・バーを使用することを決めます。

と、ユーザーを押す特定のタブバーの項目では、私は特定のビューコントローラを表示したい - と私は私のコードでプログラムしたい、表示するかを選択

私はタブバーにInterface Builderでナビゲーションコントローラを追加しようとしましたが、そのビューコントローラのviewWillAppearが呼び出されていない。

私はこの機能を実装する方法を教えてください。

役に立ちましたか?

解決

それは「正しい方法」ですが、ここで私は通常、3つのタブでこれを行う方法です場合、私は知りません。

- (void)initControls {
    // Create the window.
    [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];

    // Create Tab Bar.
    tabCon = [[UITabBarController alloc] init];

    // Local array variable that holds the viewcontrollers.
    // Capacity corresponds to the number of VC's
    NSMutableArray *localVCArray = [[NSMutableArray alloc] initWithCapacity:3];

    MyFirstViewController *oneViewController = [[MyFirstViewController alloc] init];
    UINavigationController *oneNavCon = [[UINavigationController alloc] initWithRootViewController:oneViewController];
    [localVCArray addObject:oneNavCon];
    [oneViewController release];
    [oneNavCon release];

    MySecondViewController *twoViewController = [[MySecondViewController alloc] init];
    UINavigationController *twoNavCon = [[UINavigationController alloc] initWithRootViewController:twoViewController];
    [localVCArray addObject:twoNavCon];
    [twoViewController release];
    [twoNavCon release];

    MyThirdViewController *threeViewController = [[MyThirdViewController alloc] init];
    UINavigationController *threeNavCon = [[UINavigationController alloc] initWithRootViewController:threeViewController];
    [localVCArray addObject:threeNavCon];
    [threeViewController release];
    [threeNavCon release];

    // Set the tab bars array of view controllers to the localVCArray
    [[self tabCon] setViewControllers:localVCArray animated:YES];

    // Release the localVCArray, all of its contents are now retained by tabCon.
    [localVCArray release];

    // Add controls to window and show.
    [window addSubview:[tabCon view]];
    [window makeKeyAndVisible];
}

initメソッドごとのViewControllerでは、あなたのような何かを行うことができます

[[self tabBarItem] setImage:[dataSource tabConImg]];
[[self tabBarItem] setTitle:[dataSource name]];
[[self navigationItem] setTitle:[dataSource navConName]];

タブバー、タブバーにタイトル、そしてあなたナビゲーション項目のタイトルに使用されるアイコンを設定するには。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top