How to set title on the navigation bar for different buttons on a single view?
My app for iPad has 3 views. Welcome Screen -> Home screen -> Detail screen
Home screen has 6 buttons. All those buttons have different data which is shown on detail screen respective to the button pressed. I want to set a title for each button on the navigation bar of the Detail Screen. So there will be 6 titles on the navigation bar. I have tagged the buttons from 开发者_开发知识库1 to 6. pls guide thanks
If you have Navigation Controller, then all you need is to set title
property of Detail screen's View Controller. Navigation bar will automatically update it's label to current View Controller's title.
So if you have action for button :
- (IBAction)buttonPressed:(id)sender {
UIButton *button = (UIButton *)sender;
NSString *title = [button text];
DetailScreenViewController *detail = [[DetailScreenViewController alloc] initWithDetail:title];
[detail setTitle:title];
[navigationController pushViewController:detail animated:YES];
[detail release];
}
Before you push the view controller, set the title for it.
thisViewController.title = @"My Title";
[navigationController pushViewController: thisViewController animated:YES];
When updating the view with new content, update the view controller's title:
viewController.title = @"New Title";
精彩评论