How to customize UINavigationBar with XIB? - objective-c

UIViewController has a property called UINavigationItem.
So how can a UIViewController refer to UINavigationBar?
The UINavigationBar is not displayed yet till UIViewController is pushed into a UINavigationController. So it's not available in viewDidLoad.
So how do we customize it?
I added UINavigationBar to the XIB. However, how do I specify that I want to use THAT UINavigationBar rather than the one provided by UINavigationController?

I added UINavigationBar to the XIB. However, how do I specify that I
want to use THAT UINavigationBar rather than the one provided by
UINavigationController?
You don't. The navigation bar is the nav controller's responsibility -- your view controller doesn't get to swap in its own nav bar. Each view controller has a navigation item that it can set to customize simple things like title and buttons, and you can get the navigation controller's nav bar when the view controller is pushed onto the navigation stack using the controller's navigationController property.

Related

Putting a Navigation Controller inside a UIScrollView

I have a UIScrollView that houses three UIViewControllers so that I can swipe between them like the view setup in SnapChat.
In my ViewController on the very right of the UIScrollView I want the user to be able to select things and then navigate to a new page. So essentially I want the right-most UIViewController to be a Navigation Controller with a nav bar and and View Controllers I navigate to from this page should also have a nav bar and a Back button as the UIBarButtonItem in the top left as standard.
I went about it the normal way, just taking the View Controller and selecting "Embed In Navigation Controller" and looking at the storyboard it looks right, but if I run it, there's no nav bar at the top of the view controller.
I have the nav bar visibility set to "Show Navigation Bar" but still nothing.
Any help appreciated
Edit
The issue is more than likely to do with how I add the view controller to the UIScrollView which is as follows:
let settingsStoryboard = UIStoryboard(name: "SettingsView", bundle: nil)
let settingsViewController = settingsStoryboard.instantiateViewController(withIdentifier: "SettingsViewController")
self.addChildViewController(settingsViewController)
self.scrollView!.addSubview(settingsViewController.view)
So I'm only adding the view. So how would I add it as a Navigation Controller? Or can that be done?
The Problem you are facing is that you are adding your view controller directly inside the scroll view but you should add the navigation controller inside the ScrollView.
So go to story board create a StoryboardID for that navigationController which is attached to SettingsViewController and then replace the SettingViewController ID with your navigationController's Storyboard ID.
maybe use addChildViewController
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);

How to hide the NavigationBar when i use SWRevealViewController embed in UINavigationController?

When i use SWRevealViewController as initial view or not embedded in UINavigationController the result is as i expected:
but when the SWRevealViewController comes from UINavigationController tee result is:
How can i avoid the NavigationBar presented in the Rear view?
Please add the following code to the viewWillAppear: method of the viewcontroller whose navigation bar you need to hide.
[super viewWillAppear:YES];
[self.navigationController.navigationBar setHidden:YES];
[self.navigationController.navigationBar.backItem setHidesBackButton:YES];
Try, this code for rear view controller
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = YES;
}
If you really need Navigation Controller on top of SWRevealViewController:
You got to hide navigation bar from navigation controller of your SWRevealViewController.
U can do this in IB (assuming you are using Storyboards):
Select Navigation Controller in your Storyboard
Open Attributes inspector
Find section "Navigation Controller", uncheck "Shows Navigation Bar"
Next, If you want navigation bard in front view controller, then attach it to separate Navigation Controller. You will have two Navigation Controllers, think on which one you want to push - it will have different effect.

hide navigationbar of uisearchdisplaycontroller when other viewcontroller is pushed

i have a uitableviewcontroller with uisearchdisplay controller. tapping on table cell pushes another view with some content and hides the navigationbar in the pushed view controller. the view controller has it's own uitoolbar, so far everything ok. the problem is that when a search result is shown and then tapping on the table cell view pushes the viewcontroller with uitoolbar with a navigation bar above it. so two bars on the pushed view. i dont want the navigation bar to be hidden. this code works if the viewcontroller is not pushed from search result
[self.navigationController setNavigationBarHidden:YES animated:YES];
what i'm missing using uisearchdisplay controller and hiding its navigation bar when other view is pushed?
I have redesigned my app. i dont use uisearchdisplay controller. instead i use uisearchbar and tableview which works perfectly.

How can I access my UINavigationBar properties with this config?

My main view controller is embedded in a UINavigationController. On my main view I've a button heading to another View Controller, let's call it "settingsController".
The problem is that I changed my UINavigationBar's appearance in my NavigationController (with UIAppearance or subclassing UINavigationBar, nevermind).
But I don't want a custom NavigationBar in my settingsController, where I've no NavigationBar attribute in IB. So how can I change this ?
Thanks for your advices
EDIT : quickly, to sum up this :
In any view controller, you can call self.navigationController.navigationBar to get the navigation bar of the navigation controller you're currently inside.
You could try changing the appearance in viewWillAppear on your settings view controller, and putting it back again in viewWillDisappear.

How to add a navigation bar to a UITableView

I added a subview to my application. The view controller is a UITableViewController. When I open the .xib file I see the table, but I can't drag a navigation bar onto it. So once the user enters the view, they have no way of getting back to the previous screen. What can be done?
the UITableView nib representation cannot have it. You can simulate the UI in the case you have a navigationController.
If you want to have a navigation controller, your UITableView has to be pushed into the stack of navigationController.
Assuming your view controller is ViewControllerA has a navigationController, then this method will make sure you have navigation controller in your UITableView:
[viewControllerA.navigationController pushViewController:tableViewController animated:YES];