2012-11-26 67 views

回答

1

您可以設置IBActionUIButton並在行動,您可以更改導航欄標題

-(IBAction)yourBtnPress:(id)sender 
{ 
    self.navigationItem.title = @"your title"; 
} 
2

設NavBar是你的導航欄,使用

navBar.topItem.title = @"String with your title"; 

需要注意的是導航欄應該是一個IBOutlet。

1

只是給IBOutlet和行動與此每個按鈕方法

-(IBAction)btn1_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"ONE";// laso you can use self.title = @"ONE"; 
} 

-(IBAction)btn2_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"TWO"; 
} 

-(IBAction)btn3_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"THREE"; 
} 

-(IBAction)btn4_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"FOUR"; 
} 

-(IBAction)btn5_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"FIVE"; 
} 

-(IBAction)btn6_Clicked:(id)sender 
{ 
    self.navigationItem.title = @"SIX"; 
} 
1

好像大約每答案已經被覆蓋,但我想我會添加這個任何方式。我更喜歡一個IBAction的粉絲,它將標題設置爲與按鈕標籤相對應的數組中的項目。你必須添加標籤到你的所有按鈕(0 - 5),我不確定接口構建器是否允許你將多個按鈕鏈接到同一個IBAction,但你可以隨時編程!

- (IBAction)changeTitle:(UIButton *)sender 
{ 
    NSArray *temp = [[NSArray alloc] initWithObjects:@"ONE",@"TWO",@"THREE",@"FOUR",@"FIVE",@"SIX", nil]; 
    [[self navigationItem] setTitle:[temp objectAtIndex:sender.tag]]; 
    temp = nil; 
}