Building a slide out menu with container view controllers and the Storyboard. I'm very confused - ios

I'm interested in building a slide out sidebar for a view controller, and I've done a lot of reading on how to implement it. This tutorial, as well as virtually all the others go over creating child view controllers, which seems like a great way to go about it. However, it's always done in code for examples.
This post goes over how to create container view controllers in the Storyboard, but it left me confused how exactly container views work in the Storyboard, and there seems to be little in the way of explanations online.
Finally, this post went over how to implement a slide out menu with container view controllers and a Storyboard. Sounds perfect right? Well, in reading it I was confused how the author seems to use multiple container views. I thought there was supposed to be one that encompassed all of the subviewcontrollers. Is it implemented correctly in that post?
Basically, I'd love an explanation on how to implement multiple view controllers using container view controllers via the Storyboard. It's my understanding from the first tutorial that you have the view controller that contains everything, and then add view controllers to that container and then they all work together via delegates. Achieving this in Storyboards is leaving me scratching my head.

Adding a container basically adds a child view controller and its view to the main controller. I think you are not clear on two things here. First, each container can be linked to only 1 controller/view pair. So, if you want to have more than one child controllers, you must have more than one containers. Secondly, communication between parent and child controllers is handled by 'embed segues', not by delegates.

Related

Multiple child view controllers inside a uicontainerview (container view)

I would like to know how to embed multiple view controllers as child controllers of a container. I have tried to follow a few online tutorials but they all only use 2 controllers, not multiple. I have tried to convert their code to use more than 2 but have been unsuccessful. That is problem 1.
I found this great repo with very simple and easy to understand code for embedding 2 view controllers: https://github.com/mluton/EmbeddedSwapping
I tried to convert it to 3 but have not had any luck.
Problem #2 is that using this method I have not been able to navigate from one child view controller to another. I cloned the project and tried placing buttons on the child view controllers and then cntrl-drag to the next child to create a segue as one would do normally but no navigation happens when the button is tapped.
What I am trying to do in my project is display a view controller (the Start Screen) in a container view. I have a button on this view controller (Start Screen) which has a segue to Step 2 View Controller. I want Step 2 View Controller to display in the same container that Start Screen is. Then there is a button from Step 2 which goes to Step 3 and again I want it displayed in the same container view.
Are there any code samples online that do this which I can study? And/or do you happen to know how yourself and can share? I have been at this 3 days and no method I can think of has worked.
Although what you want to do is possible it's a pain to get working, ChildViewControllers are meant to be a one to one relation. If you want more you would have to add an intermediate view which connects to all the views. This intermediate view would be the one-one relation to your containerviewController.
However, based on your description I'm thinking you could fix this in a way more easy way. The flow you are describing is a typical navigation flow. Add a UINavigationController and connect that to your ContainerView, and just build your navigation stack like you would with a normal Navigation flow.

Container controller view sizing

I'm currently building a custom view controller container for my iOS project and I nearly understand what I'm doing. The one thing I'm stuck on is how do you (properly - aka not a hack) add a view controller in PART of the Parent controller's frame. See how there are multiple view controllers/views in the email app? How does one build a custom controller container that designates the location of such sub-view controllers? How do you properly add such a controller? I'd like to know the "correct" way as designated by apple (best practice).
EDIT: After looking at this some more I was thinking a possible way would be to create views with custom sizing and then push those to the parent. Is this the correct way?
You sort of answered it yourself. The view you have as an example uses a UISplitViewController to show two separate views (left and right). Each of those views has a view controller that owns it. Note that the left side includes all of the view, like the search, nav bar, and toolbar. So just create two separate view controllers and add them to a UISplitViewController and you should be golden! The views themselves are created however you normally create views. Storyboards, NIBs, or in code works.

iPAD application design with multiple visible views on the screen

I am exploring the design options for an iPAD application with multiple views on the different part of the main screen. I am going to have different ViewController for each of the view. UI is quite different from what any of the available view controllers (UISplitViewController, UINavigationController etc.) provide. I have been reading about the container extension api of UIViewController (especially addChildViewController):
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html
(Look for "Implementing a Container View Controller")
However, it seems to me that this functionality is mainly designed for applications with UI that transition from one view to another (transitionFromViewController...). In my case, all of the views are visible at the same time. However, they do interact with each other. So my questions:
Am I missing something w.r.t. container extension of View Controller? I will still probably end up using this just to keep the list of child view controllers but don't see much value.
Can you recommend any other api/pattern that I should be using?
Thank you.
You can easy access to childViewController.
self.childViewControllers will return an array with all childs.
I asked similar question couple days ago: Maybe this will help you:
Get container VC instead of view
Take a look at http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html.
Add your various view controllers to self.childViewControllers and add the views of the child controllers as subviews of self.view.

Good way in iOS to have a view outside a UITabViewController

I'm just getting back into iOS development after a year or so away and am looking for a way to have a single view above or below a UITabViewController view. The idea is to have one ad view that is used throughout the app instead of one on each tab. The constant reinitializing of the ad view seems like it would be a lot of overhead so having one persist throughout would seem to be more effective.
I've searched for this but not found much of anything so even a useful link would be appreciated.
Thanks in advance,
Jason
I see several approaches here:
Since you are setting up your view hierarchy in your application's delegate, I'd suggest creating a separate UIViewController and managing it from your app delegate. That way you can show/hide it in the main UIWindow, without having to do much work.
You can subclass UITabBarController and show the ad in the visible view controller. This is more work, but your app architecture is arguably cleaner, because your app delegate doesn't get cluttered with ad-related code.
Another option is to look into a UIViewController category, where you can manage add related code. Not necessarily the cleanest, but it keeps the ads out of both your app delegate, and your tab bar controller. (You'd add the ad view as a category property via runtime level calls and associate objects, but that gets messy.)
I'd probably go with the first approach if it were me, but I could argue for either of the other two approaches, since an ad view doesn't really necessitate it's own view controller.
How about create a parent view controller and each view controller inherits from that parent view controller? Parent view controller has a ad view or table view, so every child view controller will has those two view as well.
Okay, after spending some time trying to create and manage a customer view controller for this I stumbled on the Container View Controller capability Apple added in iOS 5. I have no need to support iOS 4 or earlier so this works good for me. There's a good description of it here (unfortunately the author never wrote part 2 with a tutorial):
Container View Controller description
And a decent tutorial is available here:
Container View Controller tutorial
Between the two of these I was able to create a good setup with an AdViewController and BodyViewController (TabBarController) contained in a Container View Controller. This gives me all the capabilities I need (at least so far).

Using a View Controller managing two other View Controllers

I have a offlineMapVC and a onlineMapVC for my application to support both online maps (using MapKit and Google Maps) and offline maps (using Route-Me).
I made my own mapVC to manage the switching of these mapVCs and be able to use the view controller as one separate view controller. Well I've done this by making the offlineMapVC and the onlineMapVC instance variables of the new mapVC witch I now use all over my application.
First off all things seem to work but. However while using this approach for a longer time I ran into some problems due my using of View Controllers in a hierarchy. I read this is the wrong way to go. What is the right way to manage the switching between two view controllers? My question seems fairly simple but I couldn't find a decent solution.
I put view controllers in view controllers, myself, and I have seen much better programmers than me doing the same thing. (See Rob Napier "iOS 5 Programming - Pushing the Limits". He mentions it frequently.) As long as you don't have more than one view controller directly controlling the same views and subviews, you should be okay with it.
Since Jonah Williams wrote that article, I think iOS 5 formalized the use of view controller hierarchy with custom content view controllers. You might consider your mapVC to be a custom content view controller and implement onlineMapVC and offlineMapVC as child view controllers.
(Apple documentation links tend to change frequenctly, so Google "Custom Content View Controller" for the documentation.)
If you can give some more context to what you mean by "switching between two view controllers" that would help answer your question. Generally, I have more than one view controller active at the same time. I don't switch between them. (I use navigation and tab bar controllers in the same applicaiton, but I assume you are aware of how those work and you're asking a different question. It's just not clear what the detials are in your case.)

Resources