我是iPhone新手。我尝试使用UITabBar
(不是UITabBarController
)创建一个简单的应用程序。当我的应用程序启动时,有一个登录页面,然后它将重定向到FilmList页面。在“FilmList”类中,我只实现了我的代码来显示标签栏。在标签栏中有四个UITabBarItem
,“主页”,“地图”,“设置”,“关于我们”。当我点击主页按钮“FilmList”类时,将加载“MapList”类用于Map“Settings”,为我们设置“关于我们”。
我的代码只在每一个工作都有效。但是当我选择主页按钮时,它没有像其他选项那样显示(所有其他项目在选中时都会变淡)。检查我的模拟器的屏幕截图。
![这是我的主页标签(但用户无法理解选择了哪一个)] [2] ![这是我的地图选项卡,此处所选视图已褪色] [3]
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(@"Tabbar selected itm %d",item.tag);
//[tabBar setSelectedItem:[tabBar.items objectAtIndex:item.tag]];
switch (item.tag) {
case 0:
{
item.enabled = false;
//[tabbarcontroller setSelectedItem:nil];
//first selected
NSLog(@"tab bar selected");
FilmList *list = [[FilmList alloc]initWithNibName:@"FilmList" bundle:nil];
[tabbarcontroller setSelectedItem:[tabbarcontroller.items objectAtIndex:0]];
[self.navigationController pushViewController:list animated:NO];
}
break;
case 1:
//second selected
{
TheatersOnMap *thonmap = [[TheatersOnMap alloc]initWithNibName:@"TheatersOnMap" bundle:Nil];
thonmap.res =resarray;
thonmap.latitude = lat;
thonmap.longitude = lon;
[self.navigationController pushViewController:thonmap animated:NO];
}
break;
case 2:
//third selected
{
LocationList *LL = [[LocationList alloc]initWithNibName:@"LocationList" bundle:Nil];
[self.navigationController pushViewController:LL animated:NO];
}
break;
case 3:
//fourth selected
{
Settings *stgs = [[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
[self.navigationController pushViewController:stgs animated:NO];
}
break;
default:
break;
}
}
-(BOOL)tabBar:(UITabBar*)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (tabbarcontroller.selectedItem.tag ==0) {
return NO;
}
NSLog(@"printing");
return YES;
}