2012-01-14 11 views
0

私のアプリには数多くのタブがあります。タブは問題なく動作していますが、私は取り除きたいと思ういくつかの警告メッセージを(上記のタイトルで)取得しています。私のコードは次のとおりです:'UITabBarItem'が 'SetAction'に応答しない可能性があります

-(void)pressItem1:(id)sender { 
    [self presentModalViewController:settingsViewController animated:YES]; 
} 

-(void)pressItem2:(id)sender { 
    [self presentModalViewController:infoViewController animated:YES]; 
} 

-(void)pressItem3:(id)sender { 
    [self presentModalViewController:aboutViewController animated:YES]; 
} 

-(void)viewDidLoad { 
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 

    CGRect frame = CGRectMake(0, 0, 480, 49); 
    UIView *v = [[UIView alloc] initWithFrame:frame]; 
    UIImage *i = [UIImage imageNamed:@"smallMenuBackground.png"]; 
    UIColor *c = [[UIColor alloc] initWithPatternImage:i]; 
    v.backgroundColor = c; 
    [c release]; 
    [mainTabBar insertSubview:v atIndex:0]; 
    [v release];  

    [settingsBarItem setAction:@selector(pressItem1:)]; 
    [infoBarItem setAction:@selector(pressItem2:)]; 
    [aboutBarItem setAction:@selector(pressItem3:)]; 

    //initialSyncSwitch = NO; 
    [super viewDidLoad]; 
} 

タブは機能していますが、私はこれらの警告が表示されないので、おそらくより良い方法があります。

よろしく、 スティーブン

答えて

2

あなたはUITabBarItemで直接アクションを設定しないでください。代わりに、それを作成するUIViewControllerUITabBarDelegateを実装する必要があります。具体的には、デリゲートを実装する必要があります。ここで

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 

を、あなたが渡されるitemに基づいてpressItem1pressItem2、などを呼び出すことができます。

+0

おかげで、私は次のコードに入れて: - (無効)タブバー:(UITabBar *)タブバーdidSelectItem:(UITabBarItem *)のTabItem { \tのNSLog(tabItem.tag、 "あなたは、選択した%dを持っています" @)。 }しかし、どのタブをタップしても、NSlogは常にtabItem.tagを0としています。 – Stephen

+0

IBでタグを設定していますか? – MarkPowell

+0

ありがとう、私はそれを設定していなかった。完了しました。 – Stephen

関連する問題