2012-12-11 74 views
2

我希望能夠將正確的導航欄按鈕更改爲具有名稱和操作的其他按鈕。在按鈕上更改導航按鈕項目

爲例:

btnOpenImage按下並rightNavButton1變爲rightNavButton2

+1

上午我得到它錯了嗎?這就像設置正確的導航項目?這裏有什麼問題? – SmallChess

回答

2
-(IBAction) btnOpenImage_Clicked:(id)sender{ 

//1. IF buttons are UIBarButtonItem then use bellow code 
        // This bellow line for Change the action(Target) 
       [rightNavButton1 setAction:@selector(rightNavButton2_Clicked)]; 

       //This bellow line For Change the Title 
       [rightNavButton1 setTitle:@"rightNavButton2_Clicked"]; 

//OR 2. IF buttons are UIButton then use bellow code 

       // This bellow line for Change the action(Target) 
       [rightNavButton1 addTarget:self action:@selector(rightNavButton2_Clicked) forControlEvents:UIControlEventTouchUpInside]; 

       //This bellow line For Change the Title 
       [rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal]; 
    } 
+0

'UIBarButtonItem'沒有明顯的@interface聲明選擇器'addTarget:action:forControlEvents:'我使用這段代碼得到了這個錯誤。任何想法爲什麼? –

+0

oh barbutton然後使用它[rightNavButton1 setAction:@selector(rightNavButton2_Clicked)]; –

+0

使用此代碼[rightNavButton1 setAction:@selector(rightNavButton2_Clicked)]; [btnAddBill setTitle:@「rightNavButton2_Clicked」];而不是從我的答案我的代碼好兄弟 –

1

試試這個:

[btnOpenImage addTarget:self 
       action:@selector(aMethod) 
    forControlEvents:UIControlEventTouchDown]; 

- (void)aMethod 
{ 
    [rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal]; 

}