views:

493

answers:

1

hi, i am new to iphone dev, i want to add a button (sign out) which remains fixed on the navigation bar's right side for every view.i.e. even when tabs of TabBar are tapped, the Sign Out button should remain fixed.

Any help/suggestions would be appreciated. Thanks

+2  A: 

Since each UIViewController has its own navigation item (a set of views in the navigation bar), you have to add the same button in each view controller's -viewDidLoad method. If the same button is used everywhere in your app, it makes sense to create a subclass of UIViewController which does just that and reuse this subclass throughout your app.

Costique
Thanks for reply,every viewController has its navigationItem,But how do apple does it.Because the moment view transitions, then also button is fixed. This means they are not adding it in every view.
What Apple's app do you mean? If I understand your question correctly, there is no navigation bar animation when you tap a tab bar button (at the bottom of the screen) because the whole UINavigationController's hierarchy is immediately replaced, including the navigation bar. However, when the navigation stack is pushed/popped with animation, there is a cross-fade effect in the navigation bar where one set of views fades out and another set fades in. Say you're pushing UIViewController B on top of controller A. If they both have the same right nav bar button you just don't see the effect.
Costique
Yeah, I see it in iPod.app, but it looks like it behaves just like anywhere else. The "Now playing" button item is in every controller's navigation item, which makes it appear as if it's not animating.
Costique
"Say you're pushing UIViewController B on top of controller A. If they both have the same right nav bar button you just don't see the effect"That is the answer. Thanks For such a great help. I was thinking that the button had been added only once but probably apple adds it in every viewController.