1
votes

I was working on a project and XCode 6 seems to bring some bugs.

To describe what I need/want : I want a fullscreen (without status bar) in some view controller Example :

VC0 (with status bar) -> VC1 (without status bar) -> VC2 (with status bar)

I have tested 2 ways, with "View controller-based status bar appearance" YES and NO.

[With YES]
I set prefersStatusBarHidden to YES in VC1 and NO in VC0, VC2
--> XCode5, all seems to work well
--> XCode6, navigation controller is broken, navigation bar have weird behaviour, if I go to VC2 via push controller, back button goes to VC0

[With NO]
I set setStatusBarHidden in VC1 in viewWillAppear and viewWillDisappear
--> XCode5, all seems to work well
--> XCode6, back button provokes "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted." in log and sometimes, I have unstable behaviour of my navigation bar.

Here a sample code of describe : https://github.com/phetsana/statusbarnavigationcontroller

Some solution about this ?

1

1 Answers

0
votes

[With YES]

In ViewController:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationItem.leftBarButtonItem = nil;
    self.navigationController.navigationBar.topItem.title = @"VC 0";
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ViewController1 *controller = segue.destinationViewController;
    self.navigationController.navigationBar.topItem.title = @"VC 1";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:controller action:@selector(backBtnClicked:)];
}

In ViewController1:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked:)];
}

and in its header file, add:

- (void)backBtnClicked:(id)sender;

I noticed that when push from VC0 to VC1, prefersStatusBarHidden method in VC1 is called before viewWillDisappear of VC0 is called. I logged the self.navigationController.navigationBar.backItem.title and self.navigationController.navigationBar.topItem.title to see what happened. When status bar is hidden in VC1, the logs is different when it is not hidden, when pop back from VC2 to VC1, the backItem becomes nil and topItem becomes the VC0's title. Which shouldn't be, so in order to keep the title of VC1, we need to set the topItem title to VC1's title when VC1 appears.

From here there are rules of displaying leftmost, middle, and right content of navigation bar.

If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack.

[With NO]

Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted

This may be caused by concurrent animation, since hiding/showing status bar and popviewController happens at the same time, after you move the code to viewDidDisappear and viewDidAppear, the warning disappears.