button does not show up in navigationBar item
I've created a project with Navigation-based Application template, and did some work and ran it.
I expected if I touch a cell, n开发者_如何学Pythonew view will show up and new icon (which is going back button) will show up on navigation-bar item too.
But for some reason, the 'back button' is not added automatically. What can be the problem??
Below is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
MessageView *detailViewController = [[MessageView alloc] initWithNibName:@"MessageView" bundle:nil];
NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
You probably haven't given your parent controller a title (just self.title = @"my name" in viewDidLoad or viewWillAppear). That's what gets filled in by default in the back button, so if you don't name it, you don't get a back button.
You are saying that MessageView is inherited from UIView. But I think if there's no problem to push into the navigation controller then it would be UIViewController's subclass.
There are some reasons for not displaying back button:-
1.) As Mackworth told that you have not given any title from which you are navigating.
2.) your Navigation Bar's back button property is set for hidden.
Otherwise back button should be appear on the navigation bar.
It seems you haven't set your Navigation Bar Title in the View from where you are navigating...
Once you set the title of navigationbar by default it will show you the back button
Use it in either ViewDidLoad or ViewWillAppear.
self.navigationItem.title=@"Set Your Title here";
精彩评论