如何更改iPhone中Tabbar中选定的选项卡项?

发布于 2024-09-12 11:08:14 字数 1585 浏览 1 评论 0原文

我已在视图控制器中以编程方式创建了选项卡栏。在我的应用程序中,最初显示选项卡栏,并且视图中有五个选项卡栏项目。使用选项卡栏,最初选择第一个选项卡项目。现在我想更改所选项目,例如最初选择第四个项目。(参见图片)
我该如何实现这一目标?

这是我的代码,

    tBar = [[UITabBarController alloc] init];

    first = [[first alloc] initWithNibName:@"first" bundle:nil];

    UINavigationController *navFirst = [[[UINavigationController alloc] initWithRootViewController:first] autorelease];

    second = [[second alloc] initWithNibName:@"second" bundle:nil];

    UINavigationController *navsecond = [[[UINavigationController alloc] initWithRootViewController:second] autorelease];

    third = [[third alloc] initWithNibName:@"third" bundle:nil];

   UINavigationController *navthird = [[[UINavigationController alloc] initWithRootViewController:third] autorelease];

   fourth = [[fourth alloc] initWithNibName:@"fourth" bundle:nil];

    UINavigationController *navfourth = [[[UINavigationController alloc] initWithRootViewController:fourth] autorelease];

   fifth = [[fifth alloc] initWithNibName:@"fifth" bundle:nil];

   UINavigationController *navfifth= [[[UINavigationController alloc] initWithRootViewController:fifth] autorelease];

   tBar.viewControllers = [NSArray arrayWithObjects:navFirst,navsecond, navthird, navfourth, navfifth,nil]; 

   [self.view addSubview:tBar.view];

   [self.navigationController pushViewController:tBar animated:NO];

请参见下图。我想要完全像这样,

图片 http://www.freeimagehosting.net/uploads/2798661c55.png

请指导我。

谢谢。

I have created tab bar programmatically in the view controller. In my application, Initially displayed the tabbar and it has five tab bar items in the view.Using tab bar, Initially first tab item is selected. Now i want to change the selected items like, fourth item is initially selected.(See the image)
How do i achieve this?

Here my code is,

    tBar = [[UITabBarController alloc] init];

    first = [[first alloc] initWithNibName:@"first" bundle:nil];

    UINavigationController *navFirst = [[[UINavigationController alloc] initWithRootViewController:first] autorelease];

    second = [[second alloc] initWithNibName:@"second" bundle:nil];

    UINavigationController *navsecond = [[[UINavigationController alloc] initWithRootViewController:second] autorelease];

    third = [[third alloc] initWithNibName:@"third" bundle:nil];

   UINavigationController *navthird = [[[UINavigationController alloc] initWithRootViewController:third] autorelease];

   fourth = [[fourth alloc] initWithNibName:@"fourth" bundle:nil];

    UINavigationController *navfourth = [[[UINavigationController alloc] initWithRootViewController:fourth] autorelease];

   fifth = [[fifth alloc] initWithNibName:@"fifth" bundle:nil];

   UINavigationController *navfifth= [[[UINavigationController alloc] initWithRootViewController:fifth] autorelease];

   tBar.viewControllers = [NSArray arrayWithObjects:navFirst,navsecond, navthird, navfourth, navfifth,nil]; 

   [self.view addSubview:tBar.view];

   [self.navigationController pushViewController:tBar animated:NO];

See the below image. I want exactly like this,

image http://www.freeimagehosting.net/uploads/2798661c55.png

Please guide me.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2024-09-19 11:08:14

试试这个:

YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 3;

或者

tBar.selectedIndex = 3;

Try this:

YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 3;

or

tBar.selectedIndex = 3;
风蛊 2024-09-19 11:08:14

如果您想以编程方式从一个项目更改为另一个项目,您也可以这样做:

[self parentViewController].yourTabBar.selectedIndex = 3;

我希望这对某人有帮助

If you want to change from a item to another programmatically you can also do this:

[self parentViewController].yourTabBar.selectedIndex = 3;

I hope this helps someone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文