2012-02-04 3 views
2

ビューベースのアプリケーションで3つの項目を持つタブバーを作成しました。
ビューが表示されたら、最初のアイテムがデフォルトで選択されます。ビューベースのアプリケーションのTabbar項目が機能しない

問題はitem1の表示が選択されていますが、表示されている表示が読み込まれません。アイテムをクリックすると、ビューが表示されます。これを整理するのを手伝ってください。ここに私のコードは...

-(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 
    } 
} 

答えて

1

..

-(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];  
    } 
0

UITabBarControllerの仕組みについてさらに調査する必要があるようです。手動でビューを変更するのではなく、UIViewControllerのインスタンスを渡す必要があります。

ちょうどそれが終わってしまった

https://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

+1

彼は 'UITabBar'、ない' UITabBarController'を使用しているように見える:クラスリファレンスの読み取りを持っています。 –

関連する問題