如何更改iPhone中Tabbar中选定的选项卡项?
我已在视图控制器中以编程方式创建了选项卡栏。在我的应用程序中,最初显示选项卡栏,并且视图中有五个选项卡栏项目。使用选项卡栏,最初选择第一个选项卡项目。现在我想更改所选项目,例如最初选择第四个项目。(参见图片)
我该如何实现这一目标?
这是我的代码,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
或者
Try this:
or
如果您想以编程方式从一个项目更改为另一个项目,您也可以这样做:
我希望这对某人有帮助
If you want to change from a item to another programmatically you can also do this:
I hope this helps someone