views:

1099

answers:

5

I have a UIViewController that is pushed onto a UINavigationController and is currently displayed. When I go to start some asynchronous task inside the view controller, I can set hidesBackButton on self.navigationItem to YES, and the back button is hidden correctly.

As soon as the task is finished, and I set hidesBackButton back to NO (on the UI thread, I might add, I've made sure of this), nothing happens. The back button remains hidden.

Has anyone seen this before? What drives me especially crazy is that in my application (the same application), in a different UINavigationController hierarchy, the exact same code works correctly!

+1  A: 

Have you tried forcing the view to refresh by calling setNeedsDisplay? Maybe the OS is not picking up the changes instantly and you need to force it.

pgb
Hmm, I wasn't aware of that, I'll give it a try.
unforgiven3
+1  A: 

Have you tried using the setHidesBackButton:animated: method instead? Perhaps that has a slightly different behavior.

Kendall Helmstetter Gelner
I'll give it a try, but it worries me that I'm doing something wrong instead in one of my UINavigationControllers, since it works in the other UINavigationController. Resorting to a different version of setHidesBackButton just seems like a band-aid.
unforgiven3
+1  A: 

i have not been able to replicate your problem on my machine. however, i faced a similar issue with tableviews even when i was updating my ui on the main thread. but calling setNeedsDisplay fixed that issue.

Can you try this and see if this works:

[self.navigationController.navigationBar setNeedsDisplay];

I guess this should work, you need to do the same, BUT ON THE NAVIGATIONBAR instead. please let me know if this worked - as i cannot test my solution because i never get this problem :-)

Raj
Hmmmmmmmm, interesting - I will give that a try. It still bothers me that this works in one of my other UINavigationControllers, though, and doesn't work in a different UINavigationController. Why would one need to be redisplayed, while the other doesn't? :-/
unforgiven3
haha - good question mate - i still havent figured out why my tableview display updates on my first view and does not on my second view ;-) i face the same problem with UIAlertViews too!!!
Raj
Haha, yeah, I've seen weird stuff like that too, *sigh*, the SDK is getting better, but it's not up to par, in my opinion.
unforgiven3
+2  A: 

Are you calling hidesBackButton = NO from a thread? All UI operations should be done on the main thread, otherwise they won't have any effect.

lostInTransit
performSelectorOnMainThread is used to shunt tasks over to the UI thread, correct?
unforgiven3
yes. that is correct. [self performSelectorOnMainThread:...]
lostInTransit
This was it! Thanks!
unforgiven3
A: 

In my case I simply had to give a title to the view, as in: self.navigationItem.title = @"Menu";

Marinus