iOS: Displaying views of other viewcontrollers - ios

So if there is a UIScrollView which should display a number of different views I'm used to creating them as different view controllers, and hooking them up in IB.
After I import them in the main view controller I add the views of the separate view controllers onto the scrollview as a subview.
Is this a good (safe) approach?
If the main view controller (owner of the scrollview) deallocates will it take care of the other instantiated viewcontrollers whose views are displayed in the scrollview?
Or should I call nil on all the separate VCs in the main VC's dealloc or viewDidDisappear?

Related

Can I use storyboard to embed UINavigationController's view inside a UIViewController?

I want to keep the top and bottom sections of my view stationary and I only want to add a navigation controller at the center of the screen.
This has been perfectly doable for a lot of years and now as everyone is so enchanted by the Storyboards, I wanted to do the same through the storyboard and it seems like it is impossible.
Is it possible anyways?
you can use Container View in the storyboard.
Container View defines a region within a view controller's view
subgraph that can include a child view controller. Create an embed
segue from the container view to the child view controller in the
storyboard.

Equivalent PreferredContentSize when using ChildViewControllers

Am trying to switch over from using UIPopoverController to ChildViewControllers on iPad. We have 4 or 5 VC's that navigate within the parent nav subview controller, all with different sizes, each time we push or pop, the parent popover resizes based on the PreferredContentSize for the vc. Now have switched over to AddChildViewController, the parent vc keeps same size, is there an equivalent PreferredContentSize for ChildViewControllers?
thanks
No, there isn't. Child view controllers are used by your custom container view controllers. It is the responsibility of the container view controller to specify what it wants from its children and to gather and act on that information.
Thanks.
Discovering there are quite a few things don't get for free with childviewcontrollers that you get with popovers, like autoresize/reposition when keyboard is shown, am doing this manually now too.
Reason needed to update, is need a full screen modal view controller over the top of the pop over view controller, so thinking was change over to child view controller and can have multiple child view controllers, where as with popover you are limited to the one on the screen, tried mixing the two but popovervc is always on top.

What is the correct way to handle multiple view controllers on the same screen?

I'm having a view controller, that has few controls and images, and is located on top of the screen. I will have a space below it for child view controllers and their views.
I will show one child view controller at a time, what is a good way to do that?
Total amount of child view controllers is around 6, they are very different, so reusing some container view controller won't really work.
When pressing some button on these controllers I will move to next one.
Should I make some property, let's say contentView that will hold a view of the controller that is currently on screen?
How do I handle rotation if I don't use auto layout?
EDIT: This is more a theory question, I know of methods addChildViewController and know the way how I add views and controllers to their parents. I just want to know the good way to do that.
It depends somewhat on how you want to transition between the different child view controllers, but your question already lists a good approach.
You definitely want a different view controller for each of the children. Add a container view to your top level view. This view is where rotation and auto-resizing are handled. The contents of this view could be the child view controllers views themselves (and you control the transitions using one of the methods like transitionFromView:toView:duration:options:completion:) or the container view could hold a UINavigationController and you just push the child view controllers into it.
Whatever the container view holds, you need to take care if any of your child view controllers tries to present another view controller as a modal. The presented view controller needs to be presented by the view controller at the top of the hierarchy or the presented view may no interact correctly or truly be presented in front of other screen elements.

How to organize Controllers and Views (iOS)

I want my UITabBarController to be with frame (0;100;320;380).
In addition to UITabBarController I want to have a view with frame (0;0;320;100).
This view is supposed to be independent from TabBarController and always visible. When different Tabs are opened top view should remain visible, like UINavigationBar.
Is there any way to do it?
Create a UIViewController subclass, in the xib add two views, one upperview and another lowerview with the sizes you want
In the view did load of this view controller, create a UITabBarController, and add to it the view controllers you wish
then do
[lowerview addSubView:tabBarController.view];
[upperview addSubView:yourUpperView];

Segue from a scrollview

I have a UIscrollview that takes up about half of a screen. The scrollview contains a series of view controllers that have buttons that have segues to another view controller. When that segue is followed, it loads the view controller on top of the current scrollview.
I want that new view controller to act like any other modal segue would act if the button was not within a subview or scrollview. In other words, take up the whole screen.
Can you use segues from within a subview or a scrollview?
Thanks!
The scrollview contains a series of view controllers that have buttons
that have segues to another view controller.
An instance of UIScrollView can't "contain" view controllers -- it can only contain other views. It might contain views that are managed by other view controllers, but if you're using many view controllers all at the same time you may want to read Am I abusing UIViewController Subclassing?.
I ended up just using delegates and protocols between the views in the scrollview and the parent view controller and then I launch the new view from the parent view controller. Seems to be doing the trick.

Resources