我想在DetailViewController中以编程方式创建选项卡栏。我将拥有三个ViewController:


注释
专案
优惠


我想按此顺序在TabBar中显示3个项目,但是当我进入DetailView时,我要首先显示TabBar中的第二个项目(位于中间的项目)。如何创建我的DetailViewController来管理它?

最佳答案

使用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];

10-07 19:41
查看更多