Do I need multiple view controllers for the iPhone & iPad storyboards? - ios

I'm still relatively unfamiliar with all the new features of iOS 5, and what I can do in Xcode now. So, a good explanation would be appreciated.
I'm designed a single-view application and I have both an iPhone and iPad storyboard. I chose 'Single View Application' when I first started, so Xcode created a ViewController for me. Both storyboards list this view controller as their own.
Back in iOS 4 the way that I linked button actions to my view controller was to Right-Click on the button on the nib, pick the action that I wanted, then drag it over into the view controller's '.h' file, which auto-created a method/property for me.
I am confused about how to accomplish this now, since I have multiple storyboards but only one view controller. Do I need to have multiple links for each button; one for the button on the iPhone and one for the iPad? Or is there a better way to accomplish what I am trying to do now?

You do it the same way you did it in iOS4. But obviously you never built an universal app there ;-)
It's totally okay to have a single UIViewController class for two different nib files.
And if you use storyboards it's fine to use different storyboards and a single viewController too.
You can even use the same viewController for different scenes inside a single storyboard.
The connections to the viewController are saved in the nib or storyboard. So you can't overwrite them while designing the other user interface.
Open the iPhone storyboard, make your connections to actions and outlets. Then open the iPad storyboard and make totally independent connections.

In response to the first reply, I was under the impression that a view controller could only support two scenes in a storyboard layout. I say that because I found this thread.

Related

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.

How to connect iPad and iPhone UI XIB elements to same UIViewController

this may be a noob question, but I'm new to iOS programming and I didn't find an answer to my question elsewhere...
Following issue: I am programming a universal app for iPad and iPhone using IB and storyboards. The app is already set up correctly and I have an iPhone and iPad storyboard in my project and both are connected to the right (same) view controller as owner.
So far, so good...
My iPhone app is close to completion and I now want to add the iPad UI, which, apart from the layout and maybe some rearrangement of buttons and views to make use of the larger display, will have the same elements and functionality.
Now here's my problem: when I DragDrop my iPad UI element (e.g. a UILabel) to the view controller to connect it I (obviously) can't use the same name...because the iPhone one is already there.
If the item is called 'myTextField' on iPhone I'll have to call it e.g. 'myTextFieldiPad' for the iPad, which means I'll have to branch out every time I want to access the text field depending on the platform. Analogous for IBActions.
In a nutshell: same view controller, two practically identical XIB files for iPad and iPhone with identical UI elements, how?
Am I overlooking something?
Help to point me in the right direction would be highly appreciated...
Beschi
Don't create new properties using drag and drop.
You can connect controls from different xibs to the same property on your view controller using drag and drop, instead.
What I mean is, create your properties using drag & drop from iPhone's xib, and then connect your iPad xib controls to the SAME properties you created from your iPhone's xib.
Try create two classes which are children of your BaseViewController. First controller has name iPhoneViewController: BaseViewController, second - iPadViewController: BaseViewController. In IB for first (iPhone) xib you need connect first class. For second - second class. After that where you create viewcontroller you need check idiome. For iPhone create object of iPhoneViewController and for iPad - second.

Will we get frequent conflicts when using storyboard?

I think using storyboard will save us a lot of work sometimes. But when more than one mates working on the same storyboard. Is it possible that conflicts occurs frequently? When using .xib I and my workmates will have conflicts when we are working on the same .xib. So how about the storyboard? BTW:Don't tell me to use more than one storyboard. I think I prefer xib than storyboard if I need to use more than one storyboard.
If you have one big storyboard for your app, and several developers on your team will need to make changes in the storyboard, you will probably get conflicts.
If you're using xibs, you can put unrelated views in separate xibs. Then when developer A needs to change something in view 1, he just changes the xib containing view 1. And at the same time, if developer B changes something in view 2, he changes the xib containing view 2, which is probably separate from the xib containing view 1. So you don't get a conflict.
If you're using a storyboard, all the views are in one file. So developer A changes the storyboard to modify view 1, and at the same time developer B changes the storyboard to modify view 2. Boom, you get a conflict.
If your team has multiple developers working on the app user interface, you are much more likely to get conflicts if you use storyboards than if you use (carefully-separated) xibs. This is a serious problem with storyboards.
However, you can't create a table view controller with static content in a xib. You can only do that in a storyboard. So sometimes it's worthwhile to create a storyboard containing just one table view controller, in a project that uses xibs for everything else.

Using Storyboard how to interact with viewcontroller objects

I've reviewed many websites and youtube videos that have IOS 5 storyboarding information. Most of them are pretty basic and only describe how to get started with storyboarding and how to segue into other views. I'm interested in taking it a step further and actually adding custom code to the views contained within the storyboard.
Is the "normal" workflow when creating an IOS app using storyboard?
Create the layout of an app using storyboard (adding views and objects to those views).
Create viewcontroller files (.h and .m), one for each view contained within the storyboard.
Hook up the scenes from the storyboard with your own view controller subclasses by editing the "class" values in Identity Inspector.
I believe I followed those steps, but when I implemented step #3 above and ran my application, I was only able to see a black screen. The view I had created in storyboard wouldn't display.
You have the right steps. Make sure you create your .m and .h without a xib. Post your code for the view controller for your first view to get more help.
yes, this is the normal workflow. have you set the "initial viewcontroller? ?
see this image: http://dl.dropbox.com/u/31437518/Screen%20Shot%202012-01-24%20at%2012.29.34%20AM.png
It sounds like you made a storyboard file but it isn't being loaded.
Do you have the main storyboard setting in the target summary screen filled in?

Using Interface Builder and storyboards to build relationships between controllers

Is there a way to use Interface Builder on a storyboard to establish relationships between controllers. e.g. similar to the way UITabBarController allows you to click-drag connections to other UIViewControllers in the storyboard to build up the viewControllers relationship?
i.e. when you click-drag from UITabBarController to another UIViewController a popup gives you the option to choose "Relationships - viewControllers". It then draws and maintains the line between the controllers on the storyboard. I want to be able to do the same thing for my own custom controllers.
I've tried, however it's looking bleak:
How to create custom view controller container using storyboard in iOS 5
is a start (see the source code posted in the comments) but it's a work around - you don't get the relationship segues, however you do get Custom UIViewController containment.
I just thought it'd be prettier... Maybe iOS 8 will include this
All evidence seems to point to the fact that this is not possible to do, at least in versions of XCode up to 4 and iOS versions up to 5. Will update if I discover this changes.

Resources