Setting NavigationItem Prompt

I've been trying for a couple of hours now to figure out why I can't set or remove a UINavigationItem prompt, to the point where I've created a brand new project with two buttons; one to set the prompt, and one to hide it.


Setting a prompt that hasn't been already set in interface builder produces the following broken constraint errors in the console:


2019-09-19 12:11:34.103894+0100 TestPrompt[66261:29891206] [LayoutConstraints] Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want.
  Try this:
  (1) look at each constraint and try to figure out which you don't expect;
  (2) find the code that added the unwanted constraint or constraints and fix it.
(
    "",
    "",
    "<nslayoutconstraint:0x600002ef6e90 'uiview-encapsulated-layout-width'="" _uinavigationbarmodernpromptview:0x7f8ba5604a60.width="=" 0  ="" (active)="">",
    "<nslayoutconstraint:0x600002ebf2a0 'uiview-rightmargin-guide-constraint'="" h:[uilayoutguide:0x6000034a80e0'uiviewlayoutmarginsguide']-(16)-|(ltr)  ="" (active,="" names:="" '|':_uinavigationbarmodernpromptview:0x7f8ba5604a60="" )="">"
)

Will attempt to recover by breaking constraint


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.
2019-09-19 12:11:34.104578+0100 TestPrompt[66261:29891206] [LayoutConstraints] Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want.
  Try this:
  (1) look at each constraint and try to figure out which you don't expect;
  (2) find the code that added the unwanted constraint or constraints and fix it.
(
    "",
    "= UILayoutGuide:0x6000034a80e0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<nslayoutconstraint:0x600002ef6e90 'uiview-encapsulated-layout-width'="" _uinavigationbarmodernpromptview:0x7f8ba5604a60.width="=" 0  ="" (active)="">",
    "<nslayoutconstraint:0x600002ebf200 'uiview-leftmargin-guide-constraint'="" h:|-(16)-[uilayoutguide:0x6000034a80e0'uiviewlayoutmarginsguide'](ltr)  ="" (active,="" names:="" '|':_uinavigationbarmodernpromptview:0x7f8ba5604a60="" )="">"
)

Will attempt to recover by breaking constraint
= UILayoutGuide:0x6000034a80e0'UIViewLayoutMarginsGuide'.leading   (active)>
f
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.

The code which I'm using to set and hide the prompt is:


    @IBAction func showPrompt(_ sender: UIButton) {
        navigationItem.prompt = "Hello Prompt!"
    }

    @IBAction func hidePrompt(_ sender: UIButton) {
        navigationItem.prompt = nil
    }


If I set the prompt in interface builder, then the prompt is displayed when the app first runs but when it's removed with the hidePrompt code above, the text disappears but the navigation bar height remains.


Has anyone else come across this anomoly? I suspect something weird is going on as this occurs with a brand new iOS 13 project.

Replies

Long standing bug rdar://43522696


The workaround is to hide and unhide the nav bar:


    self.navigationController.navigationBarHidden = YES;
    self.navigationItem.prompt = @"New Prompt";
    self.navigationController.navigationBarHidden = NO;