I have a UINavigationController based application. I want to achieve an effect of presenting (pushing) view controller while having a part of a previous controller visible. So I want to have an effect like this:
Ideally the bottom of the second image would be a part of first controller's view.
Can this be done using UINavigationController methods, and if yes, how?
It is possible, but it requires quite a bit of efford.
Off the top of my head, I'd implement a custom container view controller, that has a UINavigationController an another custom container view controller (let's call it PreviousVCContainer) as child view controllers. See Creating Custom Container View Controllers. The "inner container view controller" would provide the view on the bottom and have the previous view controller (the one with "First title") as child view controller.
The idea is to connect the PreviousVCContainer with the UINavigationController in a way that it gets notified when the navVC is pushing or popping a vc. It would then go and look for the appropriate vc to display in the bottom view and add this vc as it's childVC.
I hope that get's you started. Let me know if you need more details on some specific points.
Related
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.
iOS5. I'm trying to create and add a new container view controller to my app - but need the parent view controller to itself be a child of the another view controller. Is this possible?
What I've tried so far results in the child and/or parent not being visible.
While I'm asking - has anyone got any good reference examples of creating container view controllers in iOS5. Btw, I've watched Apple's WWDC video.
Ok, well to answer my own question again, lol, No a Container ViewController doesn't have to be a root view controller.
My app structure is a navigation controller (let's call this vc1) with a variety of viewcontrollers pushed and popped on/off. One of these pushed view controllers (lets call it vc2) needs to have child view controllers. Originally I wanted to create a Container View Controller (let's call it vc3) and add this as a child of the pushed view controller and then add children to it (let's call this vc4 and vc5). This would have resulted in the following:
Nav Controller (vc1)
View Controller (vc2)
Container View Controller (vc3)
View Controller (vc4)
View Controller (vc5)
I couldn't get this working. So I had a rethink and tried combining vc2 and vc3. This seems to be working so far (I have got a visible view controller view).
My (so far) working structure is:
Nav Controller (vc1)
Container View Controller (vc2)
View Controller (vc3)
View Controller (vc4)
I'm a bit confused as to implementing custom view controllers. I have a view that I want to have slide down from the top of the window. The view has three buttons on it. When the button for the view to drop is tapped the view drops. And when tapped again the view slides up/goes away. I have the drop down view saved as a nib file. Would this be the best method for implementation? Or should I have the view in the main view's nib?
And could I get some direction on how I should set it up?
The usual pattern has each of the view's stored in their own XIB file and associated with their own view controller objects. You then alloc/init the new view controller and point it to its XIB and present it modally. Once its presented, its VC responds to its actions and interacts with the model and updates its own views. You can then dismiss that view controller and its views to revert back to the parent view controller.
I have noticed a pattern mentioned in SO where people alloc/init a child VC and then within their present VC they addSubview the newVC.view, but that just seems pretty unusual to me.
If you just have a subview that is being animated down to partially cover the screen, perhaps it doesn't warrant its own VC since, as I think I'm understating your usage, its actions would map to your current VC. In that case, I would either create its contents programmatically or just as another view in the XIB for your first VC and animate that down when needed.
I have been stuck on this for a few days now and it is killing me... In my viewDidLoad event, I am trying to programmatically add a full screen UINavigationController to a subview of my view controller. So far, I have only succeeded in doing two things...
1) Only a grey screen shows up
OR
2) I get something that resembles a navigation controller added to the view controller, instead of being my navigation controller from a XIB it is just a generic one... even though I loaded from the XIB. Oddly enough it is always shifted 25 pixels downward and slightly cut off.
I have read every single link on google and I can't seem to figure this out. I just created a new viewcontroller... added a UINavigationController to it... try to load that view controller and it messes up.
Any help is greatly appreciated!!!!
Instead of having the UINavigationController be a child of some other view controller, make the UINavigationController the root controller itself. The navigation controller is one of the special "container" view controllers, and it generally wants to own the whole screen and be at the root of the controller hierarchy (except in certain circumstances).
Try something like this:
UINavigationController * rootNavController = [[UINavigationController alloc] initWithRootViewController:myRootControllerInTheNavController];
[window addSubview:[rootNavController view]];
Which will obscure any existing views with the nav controller (those existing things will still be there when you -removeFromSuperview the nav controller's view). The nuclear option is to set your UIWindow's rootViewController property with the nav controller, but it sounds from your comment that this may not be what you want to do here.
Possibly a cleaner approach: If it accomplishes what you want, I believe you could also take your nav controller and present it modally (see docs for uiviewcontroller) from whatever the current view controller is. Set the transition appropriately, and while you're in the nav stack, the nav controller will be visible.
I have my views that are part of a tabBar. Each view has a navigationController.
In one of my views I have an embeded xib component. This is a scrolling view
with UIButtons inside it.
I want to slide in another view, inside the navigationController when a person taps the button. I can get the taps, etc.
BUT, I can't figure out how to find the controlling navigationController of that page to push the new view into. Nothing seems to work that I have tried.
IS this possible?
Thanks
You need to pass a reference to the navigation controller "down" your view hierarchy. Or pass another object that has a reference to the navigation controller "down". Or get the app delegate if it has a reference to the navigation controller.