Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 基于视图的应用程序中的Tabbar项不工作_Iphone_Ios_Uitabbar - Fatal编程技术网

Iphone 基于视图的应用程序中的Tabbar项不工作

Iphone 基于视图的应用程序中的Tabbar项不工作,iphone,ios,uitabbar,Iphone,Ios,Uitabbar,我通过nib在基于视图的应用程序中创建了一个包含三项的选项卡栏。 我希望在视图出现时默认选中第一个项目 问题是item1 show已选中,但它没有加载它有权执行的视图。当我们单击该项目时,将显示视图。请帮我整理一下。这是我的密码 -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; tabBar.delegate = self; [tabBar setSelectedItem:[tab

我通过nib在基于视图的应用程序中创建了一个包含三项的选项卡栏。
我希望在视图出现时默认选中第一个项目

问题是item1 show已选中,但它没有加载它有权执行的视图。当我们单击该项目时,将显示视图。请帮我整理一下。这是我的密码

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    tabBar.delegate = self;
    [tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    NSLog(@"didSelectItem: %d", item.tag);
    if (item.tag==1) {
        ImagesOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 210, 320, 250)];
        ImagesOverlay.backgroundColor=[UIColor grayColor];
        [self.view addSubview:ImagesOverlay];
    }else if (item.tag==2) {
        relatedOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 210, 320, 250)];
        relatedOverlay.backgroundColor=[UIColor redColor];  
        [self.view addSubview:relatedOverlay];
    }else if(item.tag==3){
        //other condition
    }
}

看起来您需要进一步研究
UITabBarController
的工作原理。您应该将
UIViewController
的实例传递给它,而不是手动更改视图。阅读课堂参考:

刚刚完成

   -(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
tabBar.delegate = self;
[tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
[self activateTab:1];
 }

- (void)activateTab:(int)index {
switch (index) {
    case 1:
    //condition
    break;
    case 2:
   //condition
    break;
    default:
        break;
}
 }

  - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %d", item.tag);
[self activateTab:item.tag];    
  }

他似乎在使用
UITabBar
,而不是
UITabBarController