Frage

Ich hatte eine Navigation-Controller-basierte Anwendung. Und ich beschloss Tab Bars in meiner Anwendung zu verwenden.

Wenn der Benutzer an einem bestimmten Tableiste Artikel Ich möchte einen bestimmten View-Controller angezeigt werden -. Und ich möchte programmatisch in meinem Code wählen, welche angezeigt werden

Ich habe versucht, in der Interface Builder einen Navigation-Controller in meine Tab-Leiste, aber viewWillAppear seinen View-Controller hinzufügen wird nicht aufgerufen werden.

Wie kann ich diese Funktion implementieren?

War es hilfreich?

Lösung

Ich weiß nicht, ob es der „richtige Weg“ ist, aber hier ist, wie ich dies in der Regel tue mit drei Registerkarten.

- (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];
}

In der init-Methode jedes Viewcontroller Sie so etwas wie tun:

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

Um das Symbol in der Tab-Leiste verwendet gesetzt, den Titel in der Tab-Leiste und den Titel Ihnen Navigationselement.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top