Identify the current Navigation Bar - iphone

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?

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.

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/

Related

UITabbar Controller

In my app i am using tabbar controller with 5 tabs,in 3 tabs,when click on a button it calls one View Controller. I am using same view controller for those 3 tabs so i am getting problem while calling same view in different tabs,So while changing the tab i dont want to call ViewWillAppear method. So what i have do? or else how to find previous selected index of the tabbar controller?
Thanks in Advance
I think you are not familiar with iOS Development.
In a TabbarController we can specify as much of UIViewcontroller/UINavigationController object.
if we need to re-use a UIViewcontroller you need to tag the view controller using a property object.
You need to use different instance of UIViewController for different tab.
While Showing a UIViewController its viewWillAppear got fired. we don't able to remove this behavior. But in most case we can handle such case with viewDidLoad (It is called once for an instance of view controller).
if we need to track the previously selected tab item we need to do our own work-around by using a shared class or static variable.
thanks,
Naveen Shan

Loading a custom UIView from a XIB file within a XIB for a ViewController view

I have an WizardSequenceViewController with an IBOutlet WizardView *_wizardView. In many WizardSequenceViewController.xib file I have the view outlet connected to the File's Owner - WizardSequenceViewController. I have a subview of that view defined with the class attribute set to WizardView. I have connected that WizardView to the outlet in the File's Owner. Finally, in my WizardView.xib I have a UILabel that I have placed in the file to test if the view is being rendered. When I select the WizardSequenceViewController from my tab bar, I see the superview view but not the subview _wizardView. When I set a breakpoint in my -(id)initWithCoder method in my WizardView.m file I see it stop there, so I know that it is calling that initializer (and thus it should be using the xib to load that file). I have tried many iterations and variations to get this thing to work but I can't and I am going crazy. Does anybody have any ideas?
From Apple doc "View Controller Basics, About Custom View Controllers":
The one-to-one correspondence between a view controller and the views in its view hierarchy is the key design consideration. You should not use multiple custom view controllers to manage different portions of the same view hierarchy. Similarly, you should not use a single custom view controller object to manage multiple screens worth of content.
Note: If you want to divide a view hierarchy into multiple subareas and manage each one separately, use generic controller objects (custom objects descending from NSObject) instead of view controller objects to manage each subarea. Then use a single view controller object to manage the generic controller objects.
Maybe you can't do a view-and-subview outlet setup in a view controller. And I'm not sure assigning the subview outlet to a separate NSObject subclass would work either, because how would you present it? Could you write your subview programmatically, using initWithFrame and addSubview, instead of making it an outlet? Or, if you really want to set it up graphically, could you assign it to a separate view controller as owner? Then the top view controller will call presentModal on the sub view controller. Or, if all you need is a UILabel as a subview, just add the label to the main view?
Even I faced a similar issue. But got it resolved by following steps given in the following link. Hope it helps.
http://blog.yangmeyer.de/blog/2012/07/09/an-update-on-nested-nib-loading

using UINavigationBar without UINavigationController

I want a UINavigationBar at the top of my UIWebView but I want to control by hand the title, the back button, what the back button does - etc. In other words I never want to push or pop views. I just want to change the UINavigationBar contents as the user clicks around the web view.
Where I'm up to is I added the UINavigationBar to my superView and made it 44 pixels tall. How do I set the title since I have no navigationItem? How would I set a fake back button up?
I would appreciate any pointers. I realise this is quite weird what I'm doing.
Thanks :)
The answer, if anyone's interested, is in the class reference of UINavigationBar.
When you use a navigation bar as a standalone object, you are
responsible for providing its contents. Unlike other types of views,
you do not add subviews to a navigation bar directly. Instead, you use
a navigation item (an instance of the UINavigationItem class) to
specify what buttons or custom views you want displayed. A navigation
item has properties for specifying views on the left, right, and
center of the navigation bar and for specifying a custom prompt
string.
In short, use a UINavigationItem and apply it by "pushNavigationItem" on the UINavigationBar.
I created a subclass of UINavigationBar called StaticNavigationBar which I can then load with any state by putting the appropriate UINavigationItem's on it. Thanks for all your answers people.
You can have that UINavigationBar as an outlet and then you can manupulate it as you want. So you don't have to refer to somebody's navigation item. It'll be an independent (sort of) object on your view.
If you dont want the navigationbar as-is youll have to roll your own.
if youre ok with the built in animations for pushing and popping items(dont confuse with push/pop of viewcontrollers) to the bar you would then set your UINavigationBarDelegate and use its methods for controlling how things push/pop, etc.

adding UISearchBar in Navigation based application

I have added UISearch object on view in Navigation based application.
But when i run the application, only table view is visible, why UI Search object is not visible.
Thanks in advance,
iSight
1)chech u made outlet of uisearch bar
2)u connected delegate property to uisearchj bar
3)declared all essential method of uisearch bar for eg if u just made outlet of table view but didnt made its necessory methods then table will not show or work

Add views to "more" tab item

Is it possible to change appearence of "more" item in TabBarController? For example can I add custom views and change layout of tableView containing "more" controllers list?
Just find it was already discussed in
Customizing the More menu on a Tab bar
https://discussions.apple.com/thread/2399024
So we can get instance of this "More" ViewController using:
UIViewController *moreViewController = tabBarController.moreNavigationController.topViewController;
In fact it is of undocumented class UIMoreListController declared as:
#interface UIMoreListController : UIViewController <UITableViewDelegate, UITableViewDataSource>
moreViewController.view property contain UITableView and we can use it, for example add tableHeaderView:
UITableView *moreTableView = (UITableView*)moreViewController.view;
moreTableView.tableHeaderView = myOwnCustomView;
But I am not sure is this code "applesafe"? Because it use private class although not explicitly.
And what if I want to add a view that shouldn't scroll with table? Any ideas?
yes, this is all possible, if you could give us an example of what you want, maybe with a screenshot or something, then we can help you with some code examples
You can do what you want to do...
by using UITableViewController as a moreview tabbaritem.
and can create a moreview some what similar to the standard moreView controller.