IOS SDK: Container view with 3 UI View area how to? - iphone

I'm newbie in iOS dev. I need windows with tree views on it. I created view-base application, and added UIView controls in master view. Also i added 3 View controllers for that views with view definition in separated xib files. How to link views from separated xib files with view areas on master view? Should i manually create controller instances and load controller's view into view areas? Or maybe is possible to create them in IB? Thank you.

You should be able to just drag the instances of the three controllers into the nib file of the master view, and resize them in order to create the desired layout. However, make sure that the properties on the subviews are correct or they could overlap. In the library window of IB, go to the classes tab, and drag the classes you want (View Controllers) to the nib.
I prefer that method over manually adding them through code, as it allows much better functionality with resizing such as from rotation.

Related

Loading views into NSContainerView with swift

I have a storyboard setup with the main view having a bunch of buttons and a container view and I would like for a different view to be loaded into that container view each time I press one of those buttons, kind of like a tab view controller works but without using one of those.
Also, later on I plan to have buttons inside those views that load other views replacing the views themselves.
Anyone can give me some hints?
Thanks
"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."
You mentioned NSContainerView, so I assume you're trying to do this on macOS, not iOS. Here's a useful article and code project (for iOS 6, but I was able to set up switchable subviews in iOS 9 using this as a guide):
http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
The important bits are using the embed segue, then wiring the view controllers together through a combination of viewDidLoad and prepareForSegue, and then finally loading one of the switchable view controllers (say one for each of your buttons) from the storyboard, where they are not connected to anything else.

iPhone Storyboard: different scene for portrait and landscape

If you scroll down a bit at this Apple Developer Page you'll find the section "Creating an Alternate Landscape Interface". The basic approach described there is to present a different NIB file as a modal view when orientation changes. I am using the Storyboard feature, so I don't have NIBs. How do I load a different "scene" in that case?
Besides that, I am using a Tab Bar controller, I don't want to show a modal view. I just want to replace the current portrait view with a landscape view designed with interface builder and keep my tab bar. What would be the Storyboard way to achieve the task "Creating an Alternate Landscape Interface"? Thank you.
When you add a view controller to the storyboard it comes with a view. Call that the container view. Add two views to the container view: a portrait view and a landscape view. Set the dimension of the portrait view and the landscape view appropriately using the size inspector. Add buttons, more views, labels or whatever to the portrait and landscape views as needed for your application. Then when the orientation changes hide one view and show the other.
You can setup a navigation controller and one main view. Then you can use a template view for the portrait and landscape layouts (2 additional views).
You will need to setup the controls on the main view and make sure each one has a unique tag. Your main view will not be used, instead you will copy the controls to the two template views and set them up based on how you want each view to look. The benefit to this is each view will retain its tag which becomes a very important piece of this implementation.
Doing this you use a hybrid approach in regards to writing some UI code and using Interface Builder. After getting the two templates setup, create a unique identifier for each one. You will have to write some logic to handle the view and its subviews. A recursive method to return a collection of these based on the template you choose.
The core logic in the root view controller implementation will need to check for isPortrait and based on this you will want to load the correct view based on the identifier.
Experiment with this concept and see if it works for you. The main benefits to not using two separate views with unique controls (not the shared approach with same tags) is that you maintain access to your original subviews. Any instance variables you define in your view controller that points to a text filed, label, etc... continue to do so regardless of which template view is used. This maintains the model, view, controller approach as the data structure remains unchanged.
Using this approach you can still maximize the use of interface builder, and layout the templates for each view, while still having the flexibility to to write some custom UI code if you desire. Using only interface builder can be a bit limiting at times, and writing custom code based on orientation locks you in to a bit of tedious work.
Hope this helps some.
You can make a xib file that contains 2 uiviews, one fore portrait and one for landscape.
Assign as file's owner of the xib, the same viewcontroller of the view thet you have in the storyboard.
In viewDidLoad load the xib file, and add the appropriete view for portrait or landscape.
So if you have a storyboard with many viewcontrollers, you can set the two possibility (portrait or landscape view) only in the viewcontrollers that you are interested to change the orientation.
I used this solution and work very fine !

How to create custom view controller container using storyboard in iOS 5

In iOS5 using storyboard feature I want to create a custom container which will have 2 ViewControllers embedded in it. For Example, embed Table view controller as well as a view controller both in one ViewController.
That is, one view controller will have 2 relationship:
to table view controller
to view controller which in turn will have 4 UIImage view Or UIButton in it
Is creating this type of relationship possible using storyboard's drag drop feature only & not programmatically?
,You should only have one view controller to control the scene. However, this viewController might have two other view controllers that control particular subviews on your scene. To do this you create properties in your scene viewController, in your case one for your tableViewController and one for your view. I like to keep things together so I make both these viewControllers outlets and create them in interface builder. To create them in interface builder pull in an Object from the Object library and set its type to the relevant viewController. Hook it up to the appropriate outlet you just created in your scene's viewController - Note: this is important otherwise the viewController will be released if you are using ARC and crash your app. Then hook these viewControllers up to the view you want them to control and you are done.
Alternatively you can instantiate and hop up your viewControllers in your scenes viewController should you prefer to do this.
Hope this helps.
Edit: On reflection this is not a good idea and actually goes against the HIG you should maintain only one ViewController for each screen of content and instead try to create a suitable view class and have the single view controller deal with the interactions between the various views.
There is a way to do it that isn't too hacky. It is described at the following URL for UITabBarControllers, which you could use the first view controller in the list control the first subview, and the second one control the other. Or, you can probably adapt the code to work with UISplitViewController.
http://bartlettpublishing.com/site/bartpub/blog/3/entry/351
Basically, it works by replacing the tabbarcontroller at runtime after iOS has finished configuring it.

XCode 4.1 - Multiple view within a XIB

I have created an application successfully and given it a TabBar view controller that is working as i had hoped, but have run into a glitch.
On each xib i load from the tabBar I need to create sub-views that will perform tasks as this interacts with a database (or .. will). I have created my first page and the buttons that will navigate to the views within the XIB, but do not yet nkow how to navigate between views within the XIB itself.
would it be better to have seperate XIB's that load when the buttons are hit?
OR
should i create views within the XIB's for each category and switch between them?
I am still learning and have had some confusion regarding navigation as I already have the TabBar controlling the root of the application. I have been looking for tutorials, but they all seem to start at either navigation controller as the root, TabBar as the root, and nothing like I need for option 1 above.
I can add details of the app if needed, but am looking for guidance for now.
Thank you,
Silver Tiger
To navigate between views the best way is to use a navigation controller pushing/popping separate view controllers, loaded from separate nibs. UINavigationController is a subclass of UIViewController, so you can perfectly put a navigation controller for each tab. You can also use story-boarding in the new xcode 4.2, but I recommend getting comfortable with this before doing so.

Interface Builder. Can I Build a View Hierarchy from views hosted in viewcontrollers.?

I have two nib files. parentVC.xib and childVC.xib. Each is a viewController hosting a single view.
I want to make childVC.view a subView of parentVC.view using IB and not have to resort to building the hierarchy programmatically in viewDidLoad. Is this possible?
Thanks,
Doug