Issue with Container Views in XCode - ios

I have a simple project with one view controller. I want to add two views and create a transition between the two.
I've read that I must add the two views to a container view. When I drag the container view to the Document Outline, It appears at the same level as the views. I can't get it to be higher in the hierarchy. What am I missing?
Thanks!
Martin

"container view" in this case does not mean the container view you can select from the object library (this one you need if you want to embed viewcontrollers in other viewcontrollers) but just a regular uiview. drag a regular uiview from the object library to your viewcontroller and put the views you want to animate into this container uiview.

You need to explain what you want to do more clearly. You also need to be careful to use the right terms. Views and view controllers are different animals. Pretty much everything that appears on the iOS screen is a view: Buttons, labels, text fields, switches, etc are all views. The object that manages a whole screen-full of views is called a view CONTROLLER. Do not call view controllers views.
If you want a transition where 1 view controller gets fully replaced by another, you don't want container views. You want to use a navigation controller or maybe a modal segue. If you want a second view controller's view to appear inside your first view controller's views, then you want a container view.
If you just want to add additional views (text fields, image views, buttons, etc.) to your view controller then you just drag those objects onto your first view controller's scene in your storyboard.
In order to provide more help than that you're going to have to be clearer about what you are trying to do.

Related

Modal view that does not prevent access to parent

I am trying to create a two ViewController solution where a modal view controller is presented over a UICollectionView while allowing the user to interact with the CollectionView. In this case, it is like an advanced picker, allowing the user to choose items that will populate the properties in the modal view before saving a record.
I have a presentation controller setup to present the view how and where I want, allowing full visibility to the parent view. Nothing I have tried will allow the user to interact with (scroll, tap, etc) the UIController view.
In view debugging, I see a UITransitionView that has a frame equal to the full screen. (see image) I suspect that this is the culprit. Is this even possible in iOS?
The whole point of a modal view controller is that it takes over the screen and demands that the user respond to it before doing anything else. It puts your program into a "mode" that must be dismissed before the user can go on. That is the core reason for being of a modal dialog.
If you can interact with the view controller underneath the the top view controller is no longer a modal.
What you are trying to do is wrong from a human interface standpoint, and not supported by the application framework. You need to rethink your design.
Edit:
Top-level view controllers are not designed to share the screen. If you want another view controller to cover part of the screen while the user can still interact with the view controller underneath then you should use a container view as #МаксудДаудов suggests in his answer.
I would probably put a container view on top of the rest of my view controller's content, control-drag an embed segue to the child view controller I want to display, add an outlet to the container view, and then hide the container view.
When you want to display the "picker", you could then un-hide the container view, which would reveal the child view inside and let the user interact with it, while still being able to interact with the other components in your main view controller.
There is no way allowing presented full screen view controller to interact view controller under that. Instead , add your second view controller at containercontroller at some part of first, and change first VCs collection view frame accordingly, to be able see all the list. Doing this, you will have two view controllers working together

Multiply viewcontrollers indise view

I need to create viewcontroller with segmented control and multiply controllers, that will be switched by segmented control. Also I need segmented control to be always on top of the main view. So, I thought about design with scrollview->segmented control->some view, which contains view controllers and switches them by pressing on segmented controll.
Can anyone please share some directions on how to create view and switch view controllers inside that view ?
It seems like you should use Container Views, you can have multiple container views in one view. This also helps keep your code clean and your storyboard a lot more readable.

Split view in iPad

I am trying to create an iPad app wherein I need to maintain a split view throughout the app. In the split view, the left view is static and the rightview changes according to the selection of left view. The right view in turn might contain toolbars through which I can navigate to new views, But the left view always remains same.
I might have gone in with a split view but the problem is the left view is not table view but I want to use a customised view here. Is it acceptable to do this?
Please suggest if there are any better ways make a split view without using the default split view controller.
A split view controller can have any type of view in each of its 'panes', the standard template has a table view but there is no requirement to do so. Start with the template and then edit the master view controller so it's a subclass of UIViewController, you can also remove or edit the XIB as you require.

Designing view on top of multiple embed views

I have the task to design a application that has a main view which is always visible (it has a button on it's bottom side, and when pressed a image displays on top of all views), and a set of TableControllerView's that should appear under it, and the user needs to be able to navigate through them.
I know that you can embed a view inside another, but you cannot refer more than one view to it. The current way I'm trying to do now load one TableViewController inside the embed view, and when the user clicks the cell I manually load the other controller and add it as a child of the main view, which is the RootViewController. The problem with this approach is that the navigation bar gets stuck using the root view controller, so I have to manipulate the main navigation items on each subview transition, and second is that the frame for the second view I load is coming as it had full size, making some cells be under the main view button. This way doesn't uses segues for transition, so it makes the storyboard kinda useless.
I was thinking into using a TabViewController with it's tab hidden, but wanted to ask here for a better solution.
As you discovered, a TableViewController likes to fill up the whole screen (except navigation bars, tab bars, status bar, etc. which are official Cocoa Touch GUIs). When you want a table view to fill only part of the screen, you are supposed to use a UITableView but not a UITableViewController. You set your custom view controller object (subclass of UIViewController, not UITableViewController) as the table view delegate and data source. You will need to duplicate part of the functionality of UITableViewController in your custom view controller, but it's not a lot more than you have to do already to supply the data.
You should probably follow the standard design pattern and have separate view controller objects for each of the "pages" the user can navigate to. You just have a main button and image on each of them. But I could imagine why that might not give you exactly the effect you want.

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.

Resources