6
votes

Comment ajouter uitabbar dans iPhone en utilisant l'objectif c

Comment ajouter Ajouter Uitabbar Programmatiquement pour l'application iPhone. Besoin d'une suggestion et d'un exemple de code.


2 commentaires

Je l'ai fait, mais je n'ai pas la solution pour commencer.


Max, s'il vous plaît. J'ai acheté des livres de l'objectif C et je me suis creusé pendant un certain temps et j'ai toujours des problèmes avec ces choses. Il demande comment créer un uitabbar, pas un uitabbarcontroller ... Documentation incroyable Apple ne vous dit pas comment.


4 Réponses :


8
votes
- (void) setUpTabBar {
    FirstViewController *firstViewController = [[FirstViewController alloc]init];
    firstViewController.title = @"First View";
    firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];

    SecondViewController *secondViewController = [[SecondViewController alloc]init];
    secondViewController.title = @"Second View";
    secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
    UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];

    ThirdViewController *thirdViewController = [[ThirdViewController alloc]init];
    thirdViewController.title = @"Third View";
    thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
    UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];

    ForthViewController *forthViewController = [[ForthViewController alloc]init];
    forthViewController.title = @"Forth View";
    forthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
    UINavigationController *forthNavController = [[UINavigationController alloc]initWithRootViewController:forthViewController];

    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, forthNavController, nil];
    tabBarController.delegate = self;             
    [self sizeViewToAvailableWindow:[tabBarController view]];

    [firstNavController release];
    [firstViewController release];

    [secondNavController release];
    [secondViewController release];

    [thirdNavController release];
    [thirdViewController release];

    [forthNavController release];
    [forthViewController release];
}
Here is the code for making TabBarController programmatically.
Hope this will help you.

0 commentaires

1
votes

Voici ce que vous pouvez faire

    SubClassViewController1* vc1 = [[SubClassViewController1 alloc] init];
    UINavigationController* nav1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    nav1.navigationBar.hidden = YES;
    [vc1 release]; vc1 = nil;

    SubClassViewController2* vc2 = [[SubClassViewController2 alloc] init];
    vc2.title = @"List";
    UINavigationController* nav2 = [[UINavigationController alloc] initWithRootViewController:vc2];
    nav2.navigationBar.hidden = YES;
    [vc2 release]; vc2 = nil;

    SubClassViewController3* vc3 = [[SubClassViewController3 alloc] init];
    vc3.title = @"Scan";
    UINavigationController* nav3 = [[UINavigationController alloc] initWithRootViewController:vc3];
    nav3.navigationBar.hidden = YES;
    [vc3 release]; vc3 = nil;

    SubClassViewController4* vc4 = [[SubClassViewController4 alloc] init];
    vc4.title = @"Setting";
    UINavigationController* nav4 = [[UINavigationController alloc] initWithRootViewController:vc4];
    nav4.navigationBar.hidden = YES;
    [vc4 release]; vc4 = nil;

    UITabBarController* tabBar = [[UITabBarController alloc] init];
    [tabBar setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil]];

    [self.navigationController pushViewController:tabBar animated:YES];
    [nav1 release]; nav1 = nil;
    [nav2 release]; nav2 = nil;
    [nav3 release]; nav3 = nil;
    [nav4 release]; nav4 = nil;
    [tabBar release]; tabBar = nil;


1 commentaires

Comment créer un simple uitabbar sans le contrôleur?



1
votes

Vous pouvez faire quelque chose comme: xxx

pour ajouter des éléments à celui-ci, vous pouvez écrire: xxx


0 commentaires

29
votes

ici les deux aspects ...

premier aspect ( uitabbarcontroller strong>): Ici, vous pouvez ajouter plusieurs classes (i.e ViewControlers) à l'UitabbarController comme indiqué dans les réponses précédentes ... p>

deuxième aspect ( uitabbar strong>): Ici, vous pouvez ajouter la barre à tabulation dans n'importe quel contrôleur d'affichage ... et pour cette barre d'onglets, vous pouvez ajouter plusieurs éléments uitabbar. Et vous pouvez obtenir l'action individuelle de la barre d'onglets ..... p>

Voir le code ci-dessous Pour uitabbar strong> p>

---------> Ajout d'uitabbar strong> p>

func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
    let selectedTag:Int = (tabBar.selectedItem?.tag)!
    print(selectedTag)
    switch selectedTag {
    case 0:
        print("tabBarItem1")
        //Do what ever you want here
    case 1:
        print("tabBarItem2")
        //Do what ever you want here
    case 2:
        print("tabBarItem3")
        //Do what ever you want here
    default:
        print("tabBarItem4")
        //Do what ever you want here
    }
}


3 commentaires

Belle réponse mon ami @ashok kumar s


@Yuvarajm. Assurez-vous de définir le délégué.


@Manks Ashok, matin elle-même je le répare.