2011-12-09 4 views
0

これは私のコードです。NavigationBarにCustomViewを追加する

- (void)viewWillAppear:(BOOL)animated 
{ 

    customView = [[UIView alloc] init]; 

    UIButton *btnAdd = [[UIButton alloc] initWithFrame:CGRectMake(410, -20, 30, 40)]; 
    [btnAdd setBackgroundColor:[UIColor blackColor]]; 
    [btnAdd setBackgroundImage:[UIImage imageNamed:@"oie_815362uTrAOBMX.png"] forState:UIControlStateNormal]; 
    [btnAdd addTarget:nil action:@selector(addCustomer:) forControlEvents:UIControlEventTouchUpInside]; 
    [customView addSubview:btnAdd]; 

    UIButton *btnJump = [[UIButton alloc] initWithFrame:CGRectMake(450, -20, 30, 40)]; 
    [btnJump setBackgroundColor:[UIColor blueColor]]; 
    [btnJump setBackgroundImage:[UIImage imageNamed:@"oie_8153842yVgkR6XD.jpg"] forState:UIControlStateNormal]; 
    [btnJump addTarget:nil action:@selector(showMenue:) forControlEvents:UIControlEventTouchUpInside]; 
    [customView addSubview:btnJump]; 

    UIButton *btnBarItem = [[UIButton alloc] initWithFrame:CGRectMake(300, -20, 100, 40)]; 
    [btnBarItem setBackgroundColor:[UIColor greenColor]]; 
    [btnBarItem setBackgroundImage:[UIImage imageNamed:@"oie_99342oliBc5Sy.jpg"] forState:UIControlStateNormal]; 
    [btnBarItem addTarget:nil action:@selector(showScanner:) forControlEvents:UIControlEventTouchUpInside]; 
    [customView addSubview:btnBarItem]; 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, -10, 30, 30)]; 
    [imageView setImage:[UIImage imageNamed:@"oie_972931iW4SHiZU.jpg"]]; 
    [customView addSubview:imageView]; 

    UILabel *mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -20, 80, 40)]; 
    [mainLabel setText:@"Kunden"]; 
    [mainLabel setBackgroundColor:[UIColor lightGrayColor]]; 
    [mainLabel setTextColor:[UIColor blackColor]]; 
    [mainLabel setFont:[UIFont fontWithName:@"Arial" size:18]]; 
    [customView addSubview:mainLabel]; 

    [self.navigationItem setTitleView:customView]; 
} 

- (IBAction)showMenue:(id)sender 
{ 
    NewPopUpmenu *options = [[NewPopUpmenu alloc] initWithNibName:@"PopupMenu" bundle:nil]; 
    [options.view setFrame:CGRectMake(720, 0, 300, 200)]; 
    [self.view addSubview:options.view]; 
} 

注:問題は、私が「ジャンプ」ボタンを押すと、セレクタのメソッド(showMenue :)にアクセスできないということです。

+1

あなたはそれが呼ばれていないと確信していますか?ポップアップのorigin.xは720で、iPhoneの枠内にはありません。だから、あなたのポップアップはそこにあるが表示されない –

+0

それはIpadにある、もう一つは、私はそれを押して、それは "showMenue"メソッドを呼び出さない私はデバッグを介してそれをチェックしているということです。 –

+0

あなたの 'showMenue'にNSLogを入れて(どうして' showMenu'- - )、そのメソッドが呼び出されたかどうかを確認してください。 – Kjuly

答えて

3

各ボタンのターゲットアクションペアには、nilのターゲットを指定しています。あなたのアクションメソッドが同じクラスに実装されている場合は、あなたのtargetself次のようになります。

[btnAdd addTarget:self 
      action:@selector(addCustomer:) 
forControlEvents:UIControlEventTouchUpInside]; 
// ... 
// Same for other buttons... 
// ... 

技術を、あなたはtargetパラメータのnilを指定した場合、レスポンダチェーンは、アクションに反応するオブジェクトが検索されます。あなたが抱えている問題は、あなたのshoweMenu:メソッドがあなたの行動が期待しているシグネチャではないという事実に至る可能性があります。

- (void)showeMenu:(id)sender; 

しかし、あなたが実装でIBAction戻り値の型を指定している:アクションは次のようになりますメソッドシグネチャを探しています。

+0

ありがとうStuDev!私はチェックしましたが、それは何か違いはありますが、それでもまだ動作していません... –

+0

サー!私はあなたの提案されたすべての解決策を実行しましたが、誰も正しい方法で作業していません。提案されたソリューションをXcodeで確認してからアップロードしてください。 –

+0

"Zaki Shaheen" bhaiに感謝します!問題はちょうどフレームサイズを初期化していました.........私を助けようとした皆さん、ありがとうございます。 –

関連する問題