I've created my own ProfileUIViewController class that is a UINavigationControllerDelegate. I display this view in two ways:
From an IBAction within A-UIViewController.m, as a UIModalViewController. A-UIViewController has a UINavigationBar when it's loaded, but when I display the modal, it no longer has the navigation bar.
From clicking a table cell row within B-UIViewController.m, by pushing it onto the stack. B-UIViewController has a UINavigationBar when it's loaded, and the ProfileViewController keeps the navBar as desired :)
What I am looking to do is keep the UINavigationBar when the view is loaded as a modal in case 1, filling in INSIDE the UINavigationBar instead of laying over the entire view. (IE, I would like the modal to appear within A-UIViewConroller underneath the navBar - making it a smaller size)
Can someone help me with this? Do I need to make my own custom ModalViewController class - wouldn't this be ProfileUIViewController? Does it need some instance methods that I'm not giving it? Any direction would be great:)
The navigation bar is managed by the navigation controller, not by your view controller. When you push your view controller into the navigation controller, the navigation controller uses the information in the navigationItem to determine what to put in the navigation bar. But when you display your view controller modally, it's not inside any navigation controller so there is no bar.
One simple solution for the modal case is to create a new UINavigationController with your view controller as its root view controller, and display that modally instead of displaying your view controller directly.
Related
when I created the UITableViewController within Modal Screen, I noticed that code refused to show on Navigation Bars with Title in the Modal Screen, but Full Screen has shows it with this code.
self.navigationItem.title = "Tip"
Do someone know any tricks that allow adding that Navigation Bar Title or Navigation Bar needs in Modal Screen supports.
Let me know if you know about this, thank you for helps. :)
If you have a navigation stack with one or more view controllers and one of those view controllers (let's call it A) presents a view controller B modally, B doesn't belong to the navigation stack. It is displayed by A rather than pushed onto the stack by the navigation controller.
If you want to show a navigation bar with your modal view controller, you have 2 options:
1.Add a navigation controller before the view controller you want to present modally:
Navigation Controller 1 -(root 1)-> View Controller A -(modal)-> Navigation Controller 2 -(root 2)-> View Controller B
Or, you can install a navigation bar at the top of the modal view controller.
If you just want a navigation bar for the sake of displaying a title, use option 2, otherwise, if you need a navigation stack, use option 1.
I'm working on a project which has multiple view controllers stacked in a navigation controller, similar to this:
https://youtu.be/yl2m4fDOLQo
I fear that I may end up stacking too many view controllers in one navigation controller. I understand that once there are more than 3 view controllers stacked in a navigation controller, the views are presented "modally"
First of all, what is a "modal" presentation? I looked it up in Swift documentation but I'm having some trouble understanding how it differs from the navigation stack. Second, if there is a problem, is there any way around it?
I'm new to this so help is much appreciated,
Nick
I understand that once there are more than 3 view controllers stacked in a navigation controller, the views are presented "modally"
This is false. You can have as many view controllers in a navigation stack as your app needs, as long as the device has enough memory. View controllers in a navigation stack have a navigation bar (technically, this is part of the navigation controller), a back button and (hopefully) a swipe-right gesture that allow the user to go back "up" the stack. You add a view controller to the stack by calling pushViewController(animated:) and remove it by calling popViewController(animated:) on the navigation controller.
A modal view controller exists outside of the navigation stack. It does not have a navigation bar because it's not in a navigation controller. You are responsible for adding some way to dismiss the modal, such as tapping a close button placed manually in the view controller's view somewhere. You can even add a navigation bar instance manually and put a close button in it. You show a modal by calling present(_:animated:completion:) on the currently-displayed view controller and dismiss it by calling dismiss(_:animated:completion:).
I have an iphone app consisting of a tabbar controller in the main.xib, where the tab bar controller contains navigation controllers, which are associated with corresponding view controllers. I assume this is pretty standard.
If I present a modal view controllers view from a navigation controller contained in this hierarchy, the view owned by this view controller pops up as you would expect. However, Ive noticed if I have controls (such as a button) at the very bottom of this 'modally presented' view it is rarely detecting taps. It seems as though the tabset underneath is blocking the touches. Note that when I present the modal view controllers view it fills the visible screen, it isn't sliding up from underneath the tab set.
I thought this tababar controller->navigation controller hierarchy was pretty standard, shouldn't I be able to present a modal view controller from a navigation controller in this set up without issue? I have also tried to present the modal view controller from the tab bar controller, with the same effect.
How do I present a modal view controller in an app with the tabbar controller->navigation controller hierarchy such that the lowest portion of that view can detect touches?
thanks for any help!
Check out the first answer by Harry, I believe this set-up is related to your situation. Post an update and let us know if this helps: UIView doesn't resize to full screen when hiding the nav bar & tab bar
Also, what code are you using to present the modal view?
Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.
I'm doing this:
HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];
HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = #"Title" won't work.
Thanks!
You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.
(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)
One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).
Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.
I have a Nav controller inside a custom subclass of Tab Bar controller that i created.
I want to know from within the (custom) Tab Bar whenever one of the displayed controllers attempts to hide or show the Tab Bar. (for example when pushing a VC that has its hidesBottomBarWhenPushed=YES onto the Nac controller).
In short i want to be notified of events hiding/showing the Tab Bar but could not find anything in Apple's reference. I tried looking at UITabBar, UITabBarDelegate, UITabBarController, and UITabBarControllerDelegate but all seem to only provide functionality related to the tab bar items.
Thanks in advance.
If you are using a tab bar controller, UIKit explicitly states that every navigation controller instance that will be displayed in the tab bar controller's context will be among its viewControllers property. Now every UINavigationController instance has a delegate, which defines a navigationController:willShowViewController:animated: method which lets you know when a view controller is pushed onto it.
By setting your tab bar controller as the delegate of every navigation controller that is pushed onto it, you can analyze wether the view controller being pushed has the hidesBottomBarWhenPushed property set and generate an event when this is the case.
The algorithm used to hide the tab bar controller's tab bar is as follows: when a view controller is pushed on a navigation controller which is itself contained in a tab bar controller, if any view controller in the navigation stack of the navigation controller has the hidesBottomBarWhenPushed property set, then the tab bar should be hidden.
So the tab bar is hidden when a navigation controller is selected and one of the view controllers in its stack have the hidesBottomBarWhenPushed property set.
Subclass UINavigationController and implement the setter behind hidesBottomBarWhenPushed (or subclass the UIViewController to directly subclass the hidesBottomBarWhenPushed method) and delegate the call to the UITabBar (through a direct call or a NSNotification).