I have three view controllers: A
-> B
-> C
managed by a navigation controller. A
is a transient view controller. It asks the server for something. If the server says everyhing is OK, then A
pushes B
onto the stack. B
must hide the back button because I don't want users to manually go back to A
.
// B view controller
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
self.title = @"B";
}
B
then pushes C
onto the stack when the user taps a table cell.
// B view controller
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
C *c = [[C alloc]
initWithStyle:UITableViewStyleGrouped
];
[self.navigationController
pushViewController:c
animated:YES
];
[c release];
}
.
// C view controller
- (void) viewDidLoad
{
[super viewDidLoad];
self.navigationItem.hidesBackButton = NO;
self.title = @"C";
}
If all goes well, the flow should look like this:
------------- ------------- -------------
|_____A_____| |_____B ____| | <B|__ C___|
| | => | | => | |
| loading...| | cells | | detail |
| | | | | |
------------- ------------- -----------
For some reason, C
does not show a back button to go back to B
until I rotate the device. Once rotated, the back button appears in all orientations. The problem seems to stem from B
hiding the back button and C
trying to reveal it again, because If I don't let B
hide it, I don't have this problem. So how do I get C to show the back button without forcing the user to rotate the device like a monkey?
After some searching I found this solution for iPhone 4.2 (since you posted that it works on later versions) on some old forum post.
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.navigationItem.hidesBackButton = NO;
}
Mayhaps this will help you out. (Check this out: Back button don't appear in navigationController)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With