如何设置选项卡栏项1在iPhone中默认选择? [英] How to set the Tab bar item 1 to be selected by default in iphone?
本文介绍了如何设置选项卡栏项1在iPhone中默认选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是iPhone开发的新手.我正在创建一个基于视图的应用程序.我在视图中添加了一个标签栏(而不是标签栏控制器).通过将选项卡栏项目的标签标签设置为1、2,我已在选项卡栏项目单击事件上加载了每个选项卡栏的视图.
I am new to iPhone development. I am creating a view based application. I have added a tab bar in my view (and not a tab bar controller). By setting the tag vale of the tab bar item to 1, 2, I have loaded the view for each tab bar on tabbar item click event.
我希望默认情况下选择选项卡栏1.我该怎么办?
I want the tab bar 1 to be selected by default. What should I do for that?
这是我的代码:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %d", item.tag);
[self activateTab:item.tag];
}
- (void)activateTab:(int)index {
switch (index) {
case 1:
self.tab1ViewController =[[tab1 alloc] initWithNibName:@"tab1" bundle:nil];
[self.view insertSubview:tab1ViewController.view belowSubview:tabbar1];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = tab1ViewController;
break;
case 2:
self.tab2ViewController =[[tab2 alloc] initWithNibName:@"tab2" bundle:nil];
[self.view insertSubview:tab2ViewController.view belowSubview:tabbar1];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = tab2ViewController;
break;
default:
break;
}
}
我在界面构建器中添加了选项卡栏.我可以在界面构建器中做任何事情吗?
I added the the tab bar in interface builder.Can i do any thing in interface builder?
推荐答案
[tabBar setSelectedItem:[tabBar.items objectAtIndex:item.tag]];
这篇关于如何设置选项卡栏项1在iPhone中默认选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文