Pergunta

Eu tinha um aplicativo baseado controlador de navegação. E eu decidi usar barras de guia em meu aplicativo.

Quando o usuário pressiona em um determinado item da barra de guia eu quero mostrar um determinado controlador de vista -. E quero programaticamente no meu código escolher qual visualização

Eu tentei adicionar na Interface Builder um controlador de navegação no meu bar guia, mas viewWillAppear de seu controlador de exibição não está sendo chamado.

Como posso implementar este recurso?

Foi útil?

Solução

Eu não sei se é o "caminho certo", mas aqui está como eu costumo fazer isso com três guias.

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

No método init cada viewController você pode fazer algo como:

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

Para definir o ícone usado na barra de abas, o título na barra de abas, e o título de você item de navegação.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top