Change view of detail pane on UISplitViewController - objective-c

I am working on an app to try and learn a bit more about the cocoa touch framework and am starting to use the UISplitViewController. From what I have learned so far, this has a property called viewControllers that is an array containing the master and detail view controllers for the app.
What I am trying to set up is a folder navigation system in the masterVC, then when a specific file is selected, it is opened in the detailVC. I have got the folder navigation working and can pass the details of the files between the two view controllers.
My problem is that there are several types of files that require different views to display them correctly.
For example a jpeg image will have an image viewer, whereas an html document will have a web view and a txt document will require a text editor view.
What is the best way to change the view controller of the detail pane?
Am I better to have a single View controller and swap different views in and out depending on the file type? Or is there a way to completely remove the viewcontroller and add the appropriate one in its place?
Thanks

I would think you should use multiple view controllers. There's bound to be a lot of logic in each of these individual view controllers you mentioned that should be properly contained within its own view controller.
As for displaying the appropriate view controller, you can easily add a view of a UIViewController to any UIViewControllers view, by doing: [self.view addSubview:myTextEditorVC.view]. So in other words, your detailVC could handle the logic of knowing which type of UIViewController it needs to display, instantiate that UIViewController, and display its view within the detailVC's view.
Hope this helps!

You should be swapping out different view controllers. In Xcode 6, you can use a "Show Detail" segue from the master to point to a different navigation controller that contains your different detail view.
Here's an quick example.

Related

View Controller Management in IOS

I need help with my control viewers in Xcode. In my storyboard, I created a navigation view controller. In which I created one view controller as my root view and added several objects in it.
Now in the general way, I'm trying to Ctrl + drag Element onto my View Controller. It doesn't show any Blue line like it is supposed to so.
Also I wish I can get some explanation or tutorials describing the method of creating views and controllers and linking them.
This is great tutorial to understand storyboards(single view for all the views in application) and Segues (transition between views). Go through both parts.

Rotate View which is insider another View

Today, when implementing my program i get a problem.
I have three types of views (small view). From them i make another view. (Templates)
When full view I add to viewcontroller.
As i think, willAnimateToRotation... For small views will not work correctly, because they are inside template. And template inside ViewController.
When app rotates i need to change frames for small views.
What should i do? How to perform frame change in rotation?
Views are adding to template with addSubview and template to VC also. I pass data to small view from template.
I'd translate this as a ViewController containment problem. You need to forward the rotation messages throughout your view hierarchy, otherwise it'll never reach your small views.
Best thing to do is to look at the documentation here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
Go to the "Implementing a Container View Controller" sub-heading for a description and the "Managing Child View Controllers" sub-heading for relevant code.

Splitview Control navigating views

I am working with the SplitViewController for the iPad for the first time and trying to convert me iPhone app to run on the iPad. I have a couple of cells in a section such as Name, Phone Number etc in a navigation controller that i would like to adapt to work with the split view. I essentially would like the User to view the fields they can enter on the masterview of the splitview and when they tap a cell, the corresponding view should appear in the details view on the right. Can anyone point me in the right direction to get this functionality?
If you are okay at doing some self-learning, I would suggest simply creating a Master-Detail application in XCode. IMO that has a pretty nice template of how to set up the master and view controllers in a split view, and it will properly set up your details controller to handle hiding the master when going portrait.
In your code where (I'm guessing) you push a new view on in the iPhone version, you should just check the device type (or if self.splitViewController is set), and instead of pushing a new view on, modify the detail. The detail view controller will always be set to [self.splitViewController.viewControllers objectAtIndex: 1]
If you want more fine-grain control over your split view controller (showing the Master View as part of the SplitView when in portrait, or hiding the Master in landscape as well), I'd recommend using the excellent MGSplitViewController on github

iOS 5 storyboard, programmatically determine path

I'm having trouble to achieve the following using a storyboard:
When setup is not done:
run app -> show settings view controller -> show main navigation controller
When setup is done:
run app -> show main navigation controller
So basically, I want the app to programmatically start with the settings view in certain cases, and otherwise skip right ahead to the main navigation controller.
I did manage to show the settings view with a modal style segue from the main navigation controller, but I don't know how to display it before the main navigation controller is displayed. Any ideas?
By default, the initial view controller from your main storyboard is instantiated and displayed automatically when your app starts up. To prevent this happening you need to remove the UIMainStoryboardFile setting from your info.plist file.
With no default view controller, you are now free to create one programmatically at app startup. See the UIStoryboard documentation. Use +storyboardWithName:bundle: to load the storyboard and then use –instantiateViewControllerWithIdentifier: to create the correct view controller. You will also need to create a main UIWindow and add the view controller's view to it just like you used to do with .nib based UI. Note that without the UIMainStoryboardFile setting a main window is not created for you - read the explanation.
I managed to do it a bit different:
Use a UINavigationController as the initial view controller.
Create a root view controller that will manage the decision of what to load.
Create a Storyboard Segues from the root view controller to the main view and to settings view, and give the segues proper identifiers.
Call the performSegueWithIdentifier with the proper identifier from your root view controller.
Just another solution, hope this helps.
I did something similar to amoshaviv, his advice is sound. I did it slightly different though, and I'll give some more info.
I created a custom MyInitialViewController class, derived from UIViewController, and made this the initial view controller.
In the storyboard file, I created modal segues with appropriate names to all (in my case three) possible 'real' first view controllers.
In the MyInitialViewController class, I implemented the
- (void)viewDidAppear:(BOOL)animated;
method, to first perform the check which view to switch to, and then do the correct
[self performSegueWithIdentifier:#"NameOfSegue" sender:self];
Effectively, this makes the MyInitialViewController nothing more than a switch performed when it's brought into view. I first tried doing this when loaded because I don't care for actually seeing this view, but that did not work, while viewDidAppear does.
To make this visually smooth, I tried the following. In the properties of the segues, I disabled animation. The view I left empty, and I gave it a background color matching to that of the startup image.

iOS Split View - Load XIB

I am new to making iOS apps. I want to make a Split View app so I can have topics on the left and the content on the right.
I want to be able to pull the xib file and display it on the right. How can I do this?
I have a basic one working where it changes image, but not views. I want to display the xib file relating to the selected one in the array. Any tutorial to show me how to do this would be great.
Here is the video I watched.
P.S I am new to this app development. Thanks.
A split view controller manages two view controllers.
When you create a view controller, you can specify the .xib file from which it should load its view.
It follows, then, that when the user taps on a topic, your code can create a corresponding view controller (see UIViewController's -initWithNibName:bundle: method) and set that view controller as the split view controller's detail view controller.
It's possible to have an existing view controller load a new view from a .xib using NSBundle's -loadNibNamed:bundle:owner: method, but that's usually more work with no real advantage over replacing the entire view controller.
As far as I remember, you should have access from your viewController to the property splitViewController, on which you can change the property "viewControllers" to any array containing the rootViewController at index 0 and the detailViewController (set to your new detailViewController) at index 1.
If you don't want to have sveral controller for your views, I remember having used NSBundle methods to load a nib file and assign it to a controller. I believe this is another possibility but you have to test it.