本文介绍了如何在iPhone的标签栏中更改选定的标签项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在视图控制器中以编程方式创建了标签栏.在我的应用程序中,最初显示了选项卡栏,并且视图中有五个选项卡栏项.使用选项卡栏,最初选择了第一个选项卡项.现在,我想更改选定的项目,例如,最初选择了第四项.(查看图片)
我该如何实现?
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?
这是我的代码,
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,
图片http://www.freeimagehosting.net/uploads/2798661c55.png
请指导我.
谢谢.
推荐答案
尝试一下:
YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 3;
或
tBar.selectedIndex = 3;
这篇关于如何在iPhone的标签栏中更改选定的标签项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!