Note that there are some explanatory texts on larger screens.

plurals
  1. POChange visibility of backButton dynamically in UINavigationBar
    text
    copied!<p>I have a view that is doing some calculations and I want to hide the backButton during this time.</p> <p>I use this to open a new controller that has a back button and a cancel button:</p> <pre><code>[self.navigationController pushViewController:calcController animated:YES]; </code></pre> <p>This is how I start the calculation, all in the main thread:</p> <pre><code>- (void)startSth { self.viewMode = modeRunning; [self updateButtons]; [self performSelector:@selector(doSth) withObject:nil afterDelay:0.1]; } - (void)doSth { ... self.viewMode = modeFinished; [self updateButtons]; } </code></pre> <p>And this is the method, which should switch the visibility of the buttons: </p> <pre><code>- (void)updateButtons { BOOL busy = (self.viewMode==modeRunning); self.navigationItem.hidesBackButton = busy; //back button self.navigationItem.rightBarButtonItem.enabled = !busy; //cancel button } </code></pre> <p>Problem: On the first run it works as expected, button gets hidden and then shows up again. When clicking the back button, the view gets popped. On the second run the button is missing from the start. The method updateButtons is called two times, logging the variables self.viewMode and busy shows the correct behaviour (first 1 then 0), so obviously the call to hidesBackButton is not working.</p> <p>I also tried examples with settings navigationItem.backButton to nil, using a custom empty button, calling setNeedsDisplay or setHidesBackButton:animated:, all without success. </p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload