TabBar ViewControllers按顺序显示第二个项目

时间:2013-09-10 23:38:00

标签: iphone ios objective-c uiviewcontroller uitabbarcontroller

我想在DetailViewController中以编程方式创建一个标签栏。我将有三个ViewControllers:

  1. 评论
  2. 项目
  3. 优惠
  4. 我想在TabBar中按此顺序显示3个项目,但是当我来到DetailView时,我想首先显示TabBar中的第二个项目(位于中间的那个项目)。我怎么能创建我的DetailViewController来管理它?

3 个答案:

答案 0 :(得分:3)

使用selectedIndex方法,您可以使用tebbar viewControllers数组索引设置任何“视图控制器”。 此链接也很有用http://iosmadesimple.blogspot.in/2012/09/tabbed-application-doing-it.html

self.navigationController.tabBarController.selectedIndex not working

self.tabBarController = [[UITabBarController alloc] init];

UIViewController * commentsController = [[CommentsViewController alloc] init];

UIViewController * projectsController = [[ProjectsViewController alloc] init];

UIViewController * offersController = [[OffersViewController alloc] init];

self.tabBarController.viewControllers = @ [commentsController,projectsController,offersController];

[self.tabBarController setSelectedIndex:1];

答案 1 :(得分:0)

我认为您需要创建tabBarController并选择正确的索引。

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
[self.tabBarController setSelectedIndex:1];

答案 2 :(得分:0)

您可以使您的DetailViewController继承自UITabBarViewController

然后在ViewDidload内部:

self.viewControllers = @[commentsViewController, projectsViewConroller, offersViewController];
self.selectedIndex = 1; //to move to the middle