Question

J'espère que quelqu'un peut me explane comment faire ceci:

J'ai un TabBar et deux TabBarItems, comment puis-je attatch les articles au TabBar. Je ne fais pas cela par IB parce que le TabBar est compatible uniquement ont de l'écran parce que les éléments doivent être sur le côté gauche.

thats comment je les construis:

tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController2 = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

tabBarController.tabBar.frame = CGRectMake(0, 974, 384, 50);    
tabBarController2.tabBar.frame = CGRectMake(384, 974, 384, 50);

UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
UITabBarItem *tbi2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
Était-ce utile?

La solution

Vous ne barre d'onglets pas défini les éléments directement dans la barre d'onglet. Au lieu de cela, vous attribuez un élément de barre d'onglet à la propriété tabBarItem pour chaque contrôleur de vue contenu par votre contrôleur de barre d'onglets. Ensuite, lorsque vous ajoutez vos contrôleurs de vue sur le contrôleur de barre d'onglets, le contrôleur de la barre d'onglet gérer l'affichage de vos éléments de la barre d'onglets pour vous.

UITabBarController * tabBarController = [[UITabBarController alloc] init];

UIViewController * viewController1 = [[YourViewController alloc] init];
UIViewController * viewController2 = [[YourOtherViewController alloc] init];

viewController1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
viewController2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];

tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top