PartySoft
PartySoft

Reputation: 2839

Iphone UINavigationController onchange event

i have an app that uses a navbar. What i want to acomplish is make it transparent when i push in the last view from the nav sequence, and make it opaque when i click the back button on the nav

i tried with on dealoc, but it doesn't work. My view is an UIScrollView not an UiView, but i guess that makes no difference.

As i see it, eighter i have to control the events on the nav bar, and see the type of the view with a loop or trigger some event on the "unloading" of my current view

when i push in the view i do a self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

and when it pops out i need the

self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

Upvotes: 0

Views: 2130

Answers (3)

user1732055
user1732055

Reputation: 2507

Actually the best way for this is to use UINavigationControllerDelegate. I extended UINAvigationController and set the delegate to self and used one of the methods of the UINavigationControllerDelegate protocol.

Upvotes: 1

Andiih
Andiih

Reputation: 12423

Pushing and popping a view with UINavigationController or UITabController will call the view {Will,Did}{Appear,Disappear} methods so I think you need to hook into the child view's ViewWillDisappear.

I'd architect it so that top level navigation controller sets itself as the childs delegate, and the child calls its delgate with an "I'm unloading" type function where you change the navbar style.

Upvotes: 1

Nimrod
Nimrod

Reputation: 5133

You can't really depend on dealloc to ever get called, much less when you want it. That should only be used to release retained objects.

I think you should be able to add the barStyle changes in the viewDidAppear and viewDidUDisappear methods of your view controller.

Upvotes: 0

Related Questions