Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back button does not appear in navigation bar until you rotate

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?

Update

  • Broken on two different Verizon iPhone 4 both on iOS 4.2.10
  • Fine on AT&T iPhone 3GS on iOS 5.0
  • Fine on AT&T iPhone 4 on iOS 4.3
like image 672
JoJo Avatar asked Oct 21 '11 21:10

JoJo


1 Answers

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)

like image 165
Totumus Maximus Avatar answered Sep 29 '22 03:09

Totumus Maximus