Navigation Bar is resetting when pushing a ViewController - ios

I have a little problem with my navigation bar, when I push a view, the image logo title disappears. And I would like that the logo stays at its position :
what is the best way to keep the image into my navbar ?

The UINavigationItem (where you have probably set the logo as titleView) is specific to a single view controller. This makes sense, because the title is usually supposed to describe the content of one view controller. Have you tried setting the same titleView on your second view controller? This will definitely keep the logo visible on the detail screen, however, I'm not sure if the transition is completely seamless or if it fades out/in or slides in some way.

First you need to hide the navigation item in first view controller by using-->
self.Navigation Controller.Navigation item.hidden=yes;
Then in second View Controller configure your "logo" and Corresponding "Title" by placing image view and label.
by doing this you can achieve your requirement.

Related

How to find out if view is loaded from "More" in a navigationController or from main tab?

I have a UITabBarController with many UIViewControllers resulting with a "More" TabBarItem.
One of those views has some editing functions I'd like to place in the UINavigationBar and I can replace the right and left button items, no problem. However, there seems to be an issue when you move that view controller where the navigation controller is no longer displayed. I believe I can solve the issue if I know from where the view is loaded from.
Here is my challenge I need some direction on:
What is the best way to check to see if the selected view is not being presented with the top navigation bar? Meaning, there is no "< More" on the top. That way I can display my own Edit button.
Any view controller can ask for its tabBarController. From there, it can get the tab bar controller's moreNavigationController. So now it can ask whether its parent is the moreNavigationController.
Should be able to check if there is a left bar button item using
navigationItem.leftBarButtonItem == nil
or
navigationController?.navigationItem.leftBarButtonItem == nil
depending on your hierarchy.

Xcode 6 - Swift - Custom Tabbar with Navigation

I'm trying to create a tabbed application with navigation elements inside the tab bar, as seen in the picture below (the red bar) using Swift/XCode 6.2. Basically those three icons in the middle will direct the user to different view controllers. The other two icons would be context-based. For example, on a table view page you would see the menu icon and add new icon as seen in the image. However, clicking on a row would change the menu icon to a back icon, and the add icon to something else.
That's the general idea, but I'm having a very hard time implementing something even close to this. The first issue is that whenever I embed a view in a Tab Bar Controller, I can't move the tab bar to the top. However, when I create a custom UITabView in a View Controller, Control + Click and dragging a Tab Bar Item to another view doesn't create a segue. I haven't even begun to tackle having the navigation elements inside the bar.
I guess what I'm asking is just for a little guidance on what route to take to tackle this. I'm assuming I can't use a Tab Bar Controller or Navigation Controller because it doesn't seem like I can customize them all that much. So custom Tab Bar and Navigation Bars, and then implemnt the segues and button changes programmatically?
Thanks.
I will try to guide you from an architectural perspective (so you won't find much code below).
Using a UITabBarController
In order to achieve what you are suggesting, you are right you cannot use a UITabBarController straight away, among several reasons, the most immediate one is that they are meant to be always at the bottom and you want it in top (check Apple's docs). The good news is that probably you don't need it!
Note: If you still want to go with a UITabBarController for whatever reason, please see #Matt's answer.
Using a UINavigationController
You can use a UINavigationController to solve this task, since the UINavigationBar of a UINavigationController can be customized. There are multiple ways on how you can organize your view's hierarchy to achieve what you propose, but let me elaborate one option:
To customize a UINavigationBar's to add buttons, you just need to set its navigationItem's title view:
// Assuming viewWithTopButtons is a view containing the 3 top buttons
self.navigationItem.titleView = viewWithTopButtons
To add the burger menu functionality on a UINavigationController you can find several posts on how to do it and infinite frameworks you can use. Check this other SO Question for a more detailed answer (e.g. MMDrawerController, ECSlidingViewController to mention a couple).
About organizing your view hierarchy, it really depends on if when the user taps one of the main top buttons, it will always go to the first view controller in the new section or if you want to bring him back to the last view in the section where he was.
3.1 Switching sections displays the first view of the new section
Your app's UIWindow will have a single UINavigationController on top of the hierarchy. Then each of the 3 top buttons, when tapped, will change the root view controller of the UINavigationController.
Then, when the user changes section, the current navigation hierarchy is discarded by setting the new section view controller as the UINavigationController root view controller.
self.navigationController = [sectionFirstViewController]
3.2 Switching sections displays the last displayed view in the new section
This will require a slightly modified version of the above, where your each of your sections will have its own UINavigationController, so you can always keep a navigation hierarchy per section.
Then, when the user taps one of the top buttons to switch section, instead of changing as previously described, you will change the UIWindowroot view controller to the new section's UINavigationController.
window.rootViewController = sectionNavigationController
Using a custom implementation
Of course, the last and also very valid option would be that you implement yourself your own component to achieve your requirements. This is probably the option requiring the biggest effort in exchange of the highest customizability.
Choosing this option is definitely not recommend to less experienced developers.
I'd like to take a stab at this--I think it is possible to use a tab bar controller here.
Your topmost-level view controller will be a UITabBarController with a hidden UITabBar.
Each tab is contained in a UINavigationController.
All view controllers in the navigation controller will be a subclass of a view controller (say, SwitchableViewController).
In SwitchableViewController's viewDidLoad, you set the navigation item's title view (i.e. whatever's at the center; self.navigationItem.titleView) to be the view that holds the three center buttons. Could be a UISegmentedControl, or a custom view.
Whenever you tap on any of the buttons, you change the topmost UITabBarController's selected index to the view controller you want to show.
Issues you may encounter:
Table views inside tabs will have a scrollIndicatorOffset at the bottom even if the tab bar is hidden.
Solution: Play around with the automaticallyAdjustsScrollViewInsets of the tab bar controller, or the inner view controller. https://stackoverflow.com/a/29264073/855680
Your title view will be animated every time you push a new view controller in the navigation stack.
Solution: Take a look at creating a custom transition animation for the UINavigationController.

IOS using different navigation bars

I'm creating an application where I need to use two different navigation bars. When the application first opens up, the nav1 bar should be displayed with an image and a Login button .. when they login screen appears, there is no nav bar. After login, it goes to a Detail screen where I need to show a back arrow image, a screen title and a menu button with drop down options.
I'm using one View_Controller that all my Views inherit from. I've been working on this for days and I'm so lost, please help.
I'm a little confused about the structure of your app.
As I understand it, you want an initial view that is contained in a UINavigationController. Once someone taps the "Login" UIBarButtonItem on the UINavigationBar, then you have a view come up that is not contained in a UINavigationController (probably because it is a modal view that is outside the navigation flow of your app).
The part I'm confused about is where the Detail view comes in. Is the modally presented view dismissed while the Details view is pushed onto the navigation stack from the initial view? Why does the Details view need a back button? Does going back to the initial view effectively log out the user?
At any rate, you should be able to change the UINavigationBar for every view that is pushed on to the stack (that is also contained in your UINavigationController). If you are using Storyboard, you need to make sure that you embed the views pushed on to the stack in a UINavigationController. You can do that by going to the "Editor" menu, selecting "Embed in" and then selecting "Navigation Controller".
Let me know if I didn't understand your question or if you can post more details.
Navigation bar will be the same in the app. You can hide it, show it, change title, change background color, or background image on each view depending on your requirements. But there is only one navigation bar in navigation based apps.

Setting the Navigation Bar to cover the Status bar in Modal Segues

This could be a stupid question but i couldn't figure it out.
When i create a Push Segue it automatically should give me this if has a nav controller
while when i create a Modal Segue i need to set a navigationBar from the palette and looks like this
How can i make a custom navBar dragged from the palette to look like the first one?
I need this because i set the Status Bar text to white in order to be in contrast with the navigation bar color, but in this was the status bar is invisible, being white on the white background
You could add a property to the offset and height constraints. Then in the viewWillAppear method, set the constraints value to be -20 and 64 respectively
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear];
[self.myNavBarTopConstraint setConstant:-20];
[self.myNavBarHeightConstraint setConstant:64];
}
The problem is that you are creating your own title bar.. what you should do.. instead of presenting modally the destination view controller... present modally a navigationcontroller.. that has the destination view controller set as root view controller.
hope you can understand what tried to say =P!
GL HF
hope this helps

Slide viewController in navigation controller

I'd like to use a slide up / down effect to display various viewControllers inside a navigation controller. A few other apps do this like square, and every day. Basically when the app loads, I want to display a base view in the navigation controller. Then slide up another view controller over top of it. When then hit a button in the nav bar, I want to slide that down and show the base controller, all the while retaining the navigation bar, and changing up nav items.
Originally I tried to make this work by showing a modal but that requires using a new nav bar.
Has anyone done this, or knows of a good example that illustrates this UI pattern? Thank you!
You could have UIViews in a UIScrollView

Resources