UIContainerView requires what version of iOS? - ios

I've been digging online and in Apple's docs, but I can't seem to identify what iOS version is required to use UIContainerView. I'm a little frustrated that this tidbit of information is eluding me...

UIContainerView does not exist as a class.
According to the about page of the uicontainerview tag in StackOverflow:
There is no UIContainerView class, but there is a pattern that uses a UIViewController as a container for one or more ViewControllers. This pattern is also in the Xcode object library with the name Container View.
See, for example, the answers to this question:
There is no such class called UIContainerView. You need to create an outlet of UIView and connect that to your container view.
It is confusing because IB lablels it as UIContainerView, but it's type is really just a UIView.

Related

Can't find Container View Object

Am I the only one who can't find the Container View object in Xcode 7??
I used this feature before and now I want to implement it again an I can't find it.
I was wondering if maybe now is deprecated but it's still on Apple official documentation.
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
What I'm trying to do is to reproduce Snapchat navigation view, I'm having an scrollView with paging that will contain 3 View Controllers on each page. I want to use the container to add every child view controller.
To echo the answer that user Raj Tandel posted in a comment, apparently you cannot use container views with xibs.
Here is a great thread that explains why:
It is not possible as it needs to deal with parent and child view relationship which is not meant for xib(s)
The solution is to "just add a plain UIView to the xib to act as a container. Then in code, add your child view controller's view as a subview of the container"
For further info, click the included link above (in an effort to keep good answers and threads continuous, rather than repeating what already exists)

UIView vs Container View

So here is the problem I am trying to solve.
In each viewController I am trying to insert ads and the actual control elements. I finished couple of tutorial on raywenderlinch.com to understand that how people professionally put ads in their app. They used UIViews to have two views under mainview of view controller. So I completely understood that one subview hold the ads and another is holding actual app contents. if Ad is loaded take up the screen or else let other view have all available area.
After I came back to xcode I started coding the way I learned there. but when I was dropping UIView on storyboard, I saw containerView, which I think was not present when the tutorial was written.
So I am here to ask about the both approach and their pros and cons.
So basically its UIView vs ContainerView. Which way I should do, and why ?
Any help would be greatly appreciated.
You use UIView when you already have a view and you do not need to have a dedicated view controller to build and handle interactions within it.
From the UIView help page:
UIView object claims a rectangular region of its enclosing superview (its parent in the view hierarchy) and is responsible for all drawing in that region ...
Simplified structure:
YourViewController ---(has)---> UIView
You use UIContainerView when you need to embed another view controller in the one that you already have. The embedded view controller is in charge of returning a view for the region that the UIViewContainer occupies. Therefore, your UIContainerView knows which view controller to use to render UIView inside the region it occupies.
From the UIContainerView help page:
Container View defines a region within a view controller's view subgraph that can include a child view controller.
Simplified structure:
YourViewController ---(has)---> SubViewController ---(has)---> UIView
That SubViewController returns a view and handles its events.
As an alternative answer, you can also consider the use case instead of the technical differences. For example: Why use a container view?
A common use for container views is to reuse (share) a view, directly in the storyboard. Previously, reusing a view required creating a separate "xib" file, and programmatically adding that view when the view controller was loaded.
The above image is from this extremely simple, easy to follow guide that walks you through how to setup a container view that is shared between 2+ view controllers.
A few other thoughts on when to use it:
A navigation bar is part of a UINavigationController, which is a container view controller. So, if you wanted to build a custom alternative, you'd probably use a container view.
A container might help anytime that you want to temporarily show a complex view on top of your current VC but can't/don't want to present another VC modally. This approach still allows you to build that temporary view in interface builder, to setup auto layout constraints for it, etc
I also found a guide explaining that there's a way to switch out different container views based on the situation, allowing your VC to have sub-sections which are very dynamic, yet without having to build those sub-sections programmatically. A picture, from that guide, exhibiting what I'm referring to:
Hopefully this helps people who are trying to figure out when a container view applies to them. If you have other example use cases, please edit/add them or leave them in the comments!
If you see in detail these container view of UIView class type. To get the insights of why we need containerView you should see below portion
In most ways, a container view controller is just like a content view controller. It manages views and content, coordinates with other objects in your app, and responds to events in the responder chain. Before designing a container controller, you should already be familiar with designing content view controllers. The design questions in “Creating Custom Content View Controllers” also apply when creating containers.
for more detail about container view goto link
But before you begin you should have an understanding of
and also you can check this tutorial for how to use container view.
Thus you can go for both the approaches.
Hope this will help you. happy coding :)

UIViewcontroller in UIViewController which exceeds the bounds

I have a UIViewController having two parts:
a UIView
a bar having multiple drop down menus arranged horizontally and having thumbnail images at the top
Because second part is little complex I've decided it to be a UIViewController but now I have some concerns:
Because I have drop down menu, menu will exceeds the bounds of the bar. How can I handle it?
Is it a good way to have a UIViewController inside a UIViewController?
How can I implement a drop down menu? As far I know IOS doesn't have drop down menus.
To use a controller within another controller, you employ a custom container view controller.
See Creating Custom Container View Controllers section of the View Controller Programming Guide for iOS.
Also see the appropriate Implementing a Container Controller section of the UIViewController Class Reference.
Also refer to the WWDC 2011 video, Implementing UIViewController Containment
In iOS 6, you can set up storyboards with container views that automatically employ embed segues, saving you from needing to explicitly call addChildViewController and the like, if you're using storyboards. Check out the "container view" object in Interface Builder. If you're going to be changing the child controller, you'll have to employ the API referred to in the above links, but for the configuration of the first child, you can set that up in Interface Builder in iOS 6.
In this case, setting up a controller containment could be the right way. The only limitation is that it works for iOS 5 and greater.
Here, what you have to do:
// add as child VC
[self addChildViewController:_barViewController];
// add it to container view, calls willMoveToParentViewController for us
[_containerView addSubview:_barViewController.view];
// notify it that move is done
[_barViewController didMoveToParentViewController:self];
Here, you can find additional info Containing ViewControllers. Obviosly Apple doc is your friend. In addition, if you search for "uiviewcontroller containment" you can find a lot of tuts out there.
If your app needs to target devices where iOS 5 is not the minimum, you should rely on a UIViewController and two different views.
About drop down menus, in my opinion they don't work so well with touch interfaces. There are some alternatives, for example an instance of the UISegmentedControl class. Here you can read Apple UI design guidelines about segmented controls: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW1. If you explain a little bit more about your desired UI functionality we could offer you a better alternative from the user experience point of view.
If you insist with drop down menus, there are some third party control libraries available out there; for example: http://www.cocoacontrols.com/

Implement an view controller container without using build-in containers?

I'm new to iOS programming, so I want to dive in the View Controller Container concept.
I'm learning by "monkey see monkey do" :D and I wanted to make a Slide-Out navigation (like Facebook/Gmail/Path) nothing original.
I've found different implementations, but this one , made by Clemens Hammerl, seemed to be very simple so I started messing around with it to see whats is going on. He uses a UINavigationViewController and a UITableViewController as the ViewController's for his container (CHSlideController).
From what I've read so far, this 2 ViewController's are Containers themselves, and felt a little strange about this, so I wanted to send normal ViewController's to my Container but I cannot see the views of those ViewControllers.
The thing that I what to ask you about is, how to implement an view controller container without using other build-in containers like UINavigationViewController / UITableViewController / UITabViewController / ...?
Do I need to overwrite some methods or fallow some protocol?
Thanks.
I'm only interested from iOS SDK 5.0+.
Frankly, i don't get the purpose of this question but anyway! :-)
If it's just for learning purpose as you mentionend, then check out this rather simple example for view controller containment under iOS5+.
If you want to know why view controller containment was a PITA prior to to iOS5, check out this excelent article.
As a side note, UITableViewController is not a view controller container!
UITabBarController, UINavigationController or UISplitViewController for example are containers!

What is a ViewController?

I am a newbie, and I am wondering what a ViewController is. I've tried to look at the description, but I find it too complicated. I'm working on Xcode 3 and am trying to link two pages together.
Since you tagged this question with xcode3.2 i'll assume you're asking about UIViewController.
It's one of the UIKit Framework classes.
One of its most important properties is its view (which is an instance of UIView) that usually holds one or more subviews.
What differentiates it from simple UIView are its methods for memory management, handling appearance, implementation in UINavigationController hierarchy...
The dull information on UIViewController can be found here: UIViewController Class Reference
You're definetly want to take a look at View Controller Programming Guide for iOS and View Controller Catalog for iOS.

Resources