SplitView with multiple ViewControllers - Storyboards - iOS - ios

I have finished iPhone version of my app and want my app to support iPads as well. I used a tabbar controller for iphone.. I could use the same for iPad, however, I would have too much free space on iPad if I use a Tabbar. so I have decided to use Split View Controller. Left part(table view) should be visible all the time even if it's not in landscape mode. And every time a cell is clicked, the corresponding view should be loaded to the right hand side.. By the way I am using storyboards.. Seems like it makes everything more difficult. Are there some examples of it? Thanks..

I have faced a similar situation recently. Basically you can use the split view project template to generate the basic code. After that, I created a DetailedViewControllerContainer interface and used it as the view controller for the right side view of the split view, replacing the generated DetailViewController.
After that I created several view controllers, each of them corresponds to a selection in the left side view(master view controller). And add these view controllers as the child view controllers for the DetailedViewControllerContainer.
The catch is that you will need to use code to load the child view controllers. The benefit is that the child view controllers do not need to be modified from the iPhone version. The DetailedViewControllerContainer remains the only SplitView delegate.
Take a look at the sample code I wrote on github:
https://github.com/raoying/SplitView-Sample

Related

Multiple view controllers in a single scene?

I've been a Mac programmer since 1993 and find it somewhat hard to get into the iOS frame of mind from time to time.
I've got an iPhone app that was designed for the iPhone 5 screen size and shows 3 different views with different functionalities depending on the orientation of the device (portrait and 2xlandscape).
Now on the iPad I want to separate the landscape screen into a left part controlled by one (existing) view controller and the right part by another (existing) view controller.
As part of trying to support split screen multi-tasking I want to support size classes but my views are in xib files at the moment.. and as far as I know size classes are bound to using storyboards, so I'm migrating to storyboards which seem very ill-structured for my purposes.
I can see that the idea is
1 window = 1 root controller
and
1 screen full = 1 scene = 1 view controller.
But what I need is two (or 3) view controller in a single scene.
I've had a look at UISplitView, which seems perfect only that the left view controller has to be a navigation controller, so not what I need. Perhaps a custom collection view controller is the answer?
I'm sure I'm missing something as I'm very much stuck in a Mac mindset and haven't used storyboards before.. what's the best way of re-using my existing view controllers in this scenario?
Any advice would be very much appreciated.
Take a look at this image:
There is a component in the object library called a container view. You can connect a new view controller via a segue to that container view. Basically, you can create a parent view controller whose sole purpose is to manage/move the views of other view controllers.
The parent view controller can have outlets to container views (which are simple UIView objects) and each container view can be its own view controller.
Hope this make sense, and sends you in the right direction.

iPad Master-Detail View Using iPhone's Classes

I have an iPhone storyboard with a UITableView that segues to a detail view using a navigation controller. I'm trying to reuse my classes in the iPad version of the same app inside a master-detail UI.
Here's how my storyboards look to visualize what I'm doing:
I want to reuse as much code as possible, and so far I've been successful in reusing my PPAircraftViewController class with its aircraftTableView.
Question: Since the iPad app already uses PPAircraftViewController to hold the table and detail views, how can I reuse my PPAircraftDetailViewController class with all its code and IBOutlets?
Xcode 5, targeting iOS 6 & 7, UISplitViewController not an option since all of this is embedded within a parent navigation controller.
I finally found what I was looking for. I can't believe it took me so long to remember it, but the perfect solution for this scenario is a UIContainerView.
It lets me embed the PPAircraftDetailViewController inside its containing view controller as pictured below.
Thanks, everyone!
On the iPhone your PPAircraftDetailViewController gets pushed on the navigation stack by the PPAircraftViewController.
That makes either the one or the other visible to the user.
On the iPad, Apple provides a mechanism to show a MasterView and a DetailView side by side in a UISplitViewController.
In that case, the MasterViewController does not "push" the DetailViewController, but activates it through IBOutlets and Delegation.
You can have your PPAircraftViewController as (part of) the MasterViewController and your PPAircraftDetailViewer as (part of) the DetailViewController.
It will require some tweaking, but will also save you a lot of effort as sizing and rotating will be done by the SplitViewController.

iPad master detail app - change detail view controller's content

I started to explore the UISplitViewController class with a new master detail project in XCode, and I would like to replace the detail view's content with another UIViewControllers. I wrote it in this way (self is the detail viewcontroller and controller is the uiviewcontroller which I want to replace the first one with):
self.view = controller.view;
My question is: is it a proper way, will Apple accept it? If it is not, how could I do it better?
I am also building an iPad app with Master - Detail View Controllers in a UIIntelligentSplitViewController. As UISplitViewController doesn't support well while changing to different orientations, using UIIntelligentSplitViewController solves the issue with orientation change. See more here.
I have read on one of apple documentation and also a in best practices that we should use Only one MasterView and DetailView Controllers in entire app, and write code in such a way that all data are loaded in these two views according to the object selected.
But loading all data in same detail view might be a lot of code. So, I am also in search for answer for efficiently writing code to load in same detail view controller. However currently I am implementing only two views to show net data.
If there is any other efficient way to accomplish it, please do mention. Thanks.
You could replace the detail view controller where it is setup in your app delegate "didFinishLaunchingWithOptionsMethod". Your method would probably also work but is creating unnecessary overhead. The auto generated code they provide default's to a navigation controller on the left and a view controller on the right but you can change that to whatever you need. I have a project where I have two navigation controllers.

How to create UISplitViewController's portrait behavior in landscape orientations?

I'm trying to find a solution I've seen implemented in some iPad apps where what appears to be a UISplitViewController does not display the master view docked to the left in landscape orientation. Instead, the behavior is exactly the same in landscape as in portrait, with a UIBarButtonItem on the left side of a UIToolbar at the top of the screen bringing up a UIPopoverController with the master view controller's view. This presents some menu options that, when selected, appear to launch new UIViewController-derived classes into the detail view.
The app I'm working on needs to take advantage of as much screen real estate as possible and having the master view with the menu options docked to the left side doesn't add much value; it actually hinders the app.
So actually what I'm trying to do is two-fold:
Suppress the docked master view in landscape orientation
Have the selection of a row (menu option) in the master view load a new UIViewController-derived class into the detail view.
I've seen examples of each by themselves, respectively:
http://vimeo.com/13054813 (Hiding the Root View of a UISplitViewController)
http://bit.ly/aypcr0 (MultipleDetailViews code example from Apple)
However, I can't seem to get both of these working together.
The reason for using this approach is that I have multiple UIViewController-derived classes that I want to display when the appropriate menu option is selected. I could just instantiate them and add their views to the existing detail view and they would display fine. The problem is that none of the UIViewController lifecycle methods ever get called besides viewDidLoad (e.g. viewWillAppear:, viewDidUnload, etc.). This also includes orientation changes, and this is a big problem for the app. It seems that the only times a UIViewController-derived class acts like a UIViewController is when it is added as a subview of the app's UIWindow, or to a container class (like UINavigationController or UISplitViewController).
Am I going down the right path with the UISplitViewController, or is there a better solution?
Thanks for all of your help in advance!
Justin
This is a good UISplitViewController replacement that has the features you want (and more). It is a direct "drop in" replacement for the real UISplitViewConroller.
http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad

iPad Navigation Patterns

I've been working on an iPad application that has about 15 view controllers. Some of the view controllers are full screen, others are embedded inside the other view controllers (think split view controller).
On the iPhone navigation is very straight forward. Even if you have a ton of view controllers, you are using one of Apple's root view controllers (tab or navigation). The navigation is handled by the root view controllers and you are pretty much free to focus on your views.
On the ipad the split view and tab view controllers are not always useful, and for the app I'm working on they do not cut it. I have created separate navigation controller objects to handle hiding/show view controllers based on notifications that get posted when the user performs actions.
Anyone else have experience with solving the navigation problem on the iPad?
have you checked out MGSplitViewController by Matt Gemmell?
http://mattgemmell.com/2010/08/03/mgsplitviewcontroller-updated
I'm not claiming it'll solve all your navigation problems, but it's an interesting idea and may help you in finding more/better ways of handling view controllers.
With iOS 5 Apple has added the concept of Container View Controllers. This makes adding and removing children easy, allowing their methods for rotation/appear/disappear to be called automagically. Cool stuff!
Also, be careful using multiple view controllers for views which don't fill the full screen. Apple's documentation explicitly states that you shouldn't use view controllers for partial-screen views:
Note: You should not use view controllers to manage views that fill only a part of their window—that is, only part of the area defined by the application content rectangle. If you want to have an interface composed of several smaller views, embed them all in a single root view and manage that view with your view controller.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
Although some things might work when you have multiple view controllers managing different sub-views, other things won't work. For example, only one of your view controllers will be informed when the device is rotated. Likewise, not all your view controllers will be sent 'viewWillAppear' 'viewDidUnload' etc messages that you might expect.

Resources