Equivalent PreferredContentSize when using ChildViewControllers - ios

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.

Related

Overlapping UIViewController with another UIViewController Using Swift Programmaticaly

I have this problem and I can't seem to find the answer so I asked here. I need to overlap 2 UIViewControllers. It is in a navigation controller. Each Controllers is using xib files as view since I am not using storyboard. It needs to be overlapped since the first controller is on live feed and I cannot afford to use a screenshot for background to make the live feed stay on while the user is navigating on the second controller. Any Ideas?
try content views doc tutorial
and the VC which you want to overlap, you will not keep it in you navigation stack, you will have to make overlapping VC, child of the VC on which you want to present it, after making child you will add child VC's view as a subview to parent's view. in that way both view controllers will appear to be overlapping

iOS custom view across all view controllers

I would like to have custom view set in one screen and have it across all view controllers in my application.
I find solution with using Container view. So I create RootViewController and I give it Container view and set my original MainViewController as embed in container. I added view to RootViewController and in first view controller (MainViewController) it looks good.
The problem is when I go to another view controller by Push segue. New view controllers covers whole screen (which is okay) and covers custom view too. I was thinking that it could help if I add Navigation Controller with root MainViewController and this navigation controller would be embed in RootViewController but the result is same. I set Navigation bar as hidden (same for status bar) because I want to be hidden.
So where could be problem? Or how would you add custom view to all screens? This custom view should work as global (I am using NSTimer and counting time) so I solution with inheritance isn't for me.
You can use application window and add this custom view as subview whenever required. I have used it in one of my app to show notifications (if there area any) and it works great.
Get handle to Application Window and add subview to it. Custom view can be created from a singleton class or App delegate.
You could try it the other way round. Make a view which will never change inside your root view controller and a container view and just change the content of the container view depending what u want to display next to your unchanging view.

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.

Using iOS 6 autolayout, what would be the proper way to display somthing above an UINavigationController?

In my app, i have a main view controller which sometimes brings a modal view on top of it. This modal view is a UINavigationController with a navigation bar. I want to display an image above the navigation bar, and have the navigation bar appear below the image.
I do not want to subclass anything and the app uses autolayout, i do not want a bunch of delegate callbacks and frame calculations. The view inside the navigation controller (the actual modal content) must still respond to different screen sizes correctly, such as rotation, call status bar etc. Also, no IB solutions please, these views are all managed in code.
How do i accomplish this?
I would turn off AutoLayout and place the image at the top
I don't think you can do it with your modal view being a navigation controller. I would do it by making that modal controller a UIViewController that you set up as a custom container controller. You can add an image view to the top of this controller's view and add the view of a child view controller (which would be a navigation controller) to the bottom. This would be a lot easier to do in a storyboard using container views, but it certainly can be done in code.

Objective-C - Understanding view controllers

I understand that view controllers help control multiple views in an application, but I have trouble understanding when to use them.
If I have an application with a main page, several views with a "hierarchy" structure, and an about page not connected with the hierarchy, what files should my application have? An appdelegate, navigation controller and view controller? More than one view controller? Just a navigation controller?
Also, should they all be contained in one .xib file, or multiple .xib files?
Any help would be greatly appreciated.
Thanks.
A good habit is to have a UIViewController for each page you want to show. If I get the structure of your app you should have a main page (with many other UIViews inside it) and another page (about page). If that's true I suggest two UIViewControllers.
The UINavigationController is a subclass of UIViewController that lets you "navigate" among the pages. It's not strictly necessary but suggested (you can also implement your self a custom navigation system, but it's easier to exploit the one Apple offers you). Another navigation system is the one based on UITabBarController, if you want to take a look.
Assuming I get the structure of your app you should need two .xib file, one for each page you have.
The app delegate is conceptually different from a view controller, you'll have just a single app delegate, automatically created by Xcode (you can, of course, modify it to fit your needs).
Each "screenful of content" (Apple uses this term) should be handled by it's UIViewController or more likely a subclass of it. The point of view controller is to handle view appearing or disappearing (going on/offscreen), device rotation, memory management, navigating to other view controllers and so on. If you are creating your UI with IB, then each of those view controllers would most likely have it's own .xib file.
Each view controller has one view (it's view property) that acts as main view for each "screenful of content" to which you then add your subviews.
UINavigationController and UITabBarcontroller are there to help you control the hierarchy of your app. They only act as containers for other view controllers and don't contain any UI except navigation bar or tab bar. Using tab bar controller you can have multiple view controllers which act exactly like browser tabs. Using navigation controller you can have a stack-like navigation where new view controllers are pushed from right to left and are popped from left to right when user goes back to previous view controller. You can even have a view controller inside navigation controller inside a tab bar controller.
If you don't want to use tab bar or navigation controller, you can navigate through your view controllers by presenting them modally using presentModalViewController:animated: and dismissing by dismissModalViewControllerAnimated:. If you send YES for animated parameter of these methods, you will get an animation specified by the modalTransitionStyle property of view controller being presented or dismissed. Possible animations are slide in from bottom (default), horizontal flip of entire screen, fade in/out and half-page curl.
There are also some Apple-provided subclasses of UIViewController that help you setup your UI quicker like UITableViewController which is basically a view controller that contains a table as it's main view and conforms to 'UITableViewdataSourceanddelegate` protocols which are required to define how each cell looks and what it contains.
On iPad there is one additional container controller UISplitViewController and one additional way to present new view controllers using UIPopover.

Resources