Lauren Quantrell
Lauren Quantrell

Reputation: 2669

Identify the current Navigation Bar

I'm trying to identify the Navigation Bar in the current view so that I can add a subview to it.

I have seen this code which is able to identify the Navigation Bar that has been dynamically created and tagged:

UINavigationBar *theNavigationBar = (UINavigationBar *)[inParent.view viewWithTag:kNavigationBarTag];

But in my case the Navigation bar is not being created dynamically, so it's not tagged. Is there a way to identify it otherwise?

Upvotes: 0

Views: 160

Answers (2)

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

You set the tag property for UINavigationBar if you create or access it from your UIViewController (self.navigationController.navigationBar )

because tag is the property of UIView which is the super class for UINavigationBar ,

May be you are referring code from the below blog post ...

http://iphonesdevsdk.blogspot.com/

Upvotes: 1

Steven Kramer
Steven Kramer

Reputation: 8513

self.navigationController.navigationBar

Only valid when called from a method in a UIViewController, of course. Otherwise, try to retrieve a reference to the view controller and take it from there.

Upvotes: 1

Related Questions