Back bar doesn't show up in navigation controller
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController 开发者_StackOverflow= [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[DrinkDetailViewController release];
}
I want to have a back bar to go to my root view from the detail view. How do I do it?
There's 2 things that look a little weird here... hopefully fixing em will make the back btn show up:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES]; <-- you just pushed a viewController onto the stack, and you're immediately removing it here and going to the root
[detailViewController release]; //<-- you want to release the *instance* that you created... not the Class
}
The UINavigationController
should take care of the back button for you as far as I know. If not, I would check to see that everything is wired up correctly in your xib (if you have one). Good Luck!
With your code, it will still push to the DrinkDetailViewController but the' popToRootViewController is totally unnecessary. You should delete the line like follows..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
And I believe, the reason your back button does not show up on the nav bar is because you didn't put any title in your root view. You can put this code on you viewdidload method on the root view.
self.title = @"Your Title";
精彩评论