UISplitViewController for iphone - iphone

I want to create an iPhone (not iPad) app with a split screen view that shows two view controllers on the same screen, one on the left and one on the right of the screen (landscape only).
Is there a way to make UISplitViewController work for iPhone, or is there an open source library i can use to achieve this look?

As said, you can not use a split view controller. However, I dont think you need it anyway. Its a little cumbersome and restrictive.
You can achieve the effect of the split view controller easily using subviews. (Try to avoid using multiple view controllers as this is generally bad practice).
Create two custom views and ad them as sub views to the main view. Look at their auto resizing properties. Try to use interface builder. Show / hide you side view when the user rotates.
UISplitViewControllers aren't that useful - you can mimic their effectes easily.

There is no way you can achieve this using the UISplitViewController class. If you take a look at the Apple reference documents it clearly states that the UISplitViewController is an iPad-specific viewcontroller.
Note this point
If you are developing a universal application, though, be sure not to create and use these controllers when your application is running on an iPhone or iPod touch.

Related

Migrate app from iPhone to iPad - Not the same viewcontroller hierarchy

I have search for this question but I have found nothing, so I hope the question is not duplicated.
I have a full working iPhone app. On this app, I have two view controllers like this:
Favourites is controlled by IVFavouritesViewController and Verb list is controlled by IVFirstViewController. I want to do the same thing on a single iPad view controller, something like this:
As you can see, I have two table views, also with a UISearchBar like on the iPhone storyboard. So I want to use the iPhone viewControllers on the same view on iPad, by changing them as few as possible. What will be the best approach?
Thanks in advance!!
Well you could make a third View controller that acts like a container for the other two. It would just have two subviews which are populated with the views from your two existing controllers.

Can I use a single XIB to create full-resolution interfaces for both iPhone and iPad?

I want to load in an UISplitView an iPhone XIB, but it should be resized to full screen of the iPad... How can i do it? I dont want to convert the XIB itself!
I have read all the other solutions, but I do not want a second XIB, I just want to show it on both devices iPhone and iPad in its specific size.
So if I load it on the iPad by using the UISplitView, it should be in the full size, and if I load it on the iPhone, it should only have the iPhone size.
First off, there's no such thing as a UISplitView.
From the documentation:
The UISplitViewController class is a container view controller that manages the presentation of two side-by-side view controllers. You use this class to implement a master-detail interface, in which the left-side view controller presents a list of items and the right-side presents details of the selected item. Split view controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
So UISplitViewController is just a container. You just pass a master view controller and a detail view controller to it. The master view will be displayed in a popover controller in portrait orientation.
I think either I misunderstood you or your approach is wrong. The reason why this class is not supported on the iPhone is because it wouldn't make any sense. You can't just "resize the splitview" or whatever, you have to redesign your interface separately for the phone. It's difficult to give you any concrete suggestion without knowing what you're doing. Figure out what are you trying to achieve, have a design, make separate nibs for each device and try to reuse code and views as much as possible.
Matt Gemmell wrote a SplitViewController that you can use as subview for the iPad (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad/). You can check the source if you could use this for iPhone too. I found the source too heavy, I simply created an UITableView that loads other views when selecting a row (sort of a fake splitview).

Alternative to UINavigationController or UINavigationBar, custom height wanted

My goal is to get a navigation bar like the HBO GO app on iPad. Their nav bar has a larger height and a custom background. It seems like they're using a navigation controller since when you press on a show it takes you to a new screen with a back button.
I'm wondering either
1) Can I use an instance of UINavigationBar without a NavigationController and use the navigation bar delegate to handle pushing and popping my views?
or
2)Is there another way that I can implement this?
I am currently trying to do this with a navigation controller and navigation bar but I am running into difficulties and I think its not the best way to do it. Also Apple docs specifically say not to change the frame of the navigation bar in a navcontroller.
Ideas please? Thanks in advance!
From the looks of it, the HBO Go application uses completely custom navigation controls. A basic UINavigationController-alike class is relatively straightforward to build, but you must be careful to consider that UIViewControllers are not intended to be nested on iOS <= 4 and so you will have to pass through several methods such as view{Will,Did}appear:.
I recommend starting from the ground up, as trying to heavily customize the built-in controls will only lead to further frustrations as you run into issues or limitations in their customizability.

UIWindows or UIViews

I need three different sections in my app: a login screen, a main screen, and one that takes place in landscape mode, all totally different. I saw Apple insists that an app should have one window, so I'm asking: what would be best to use for this? Three big windows, or views?
And how should the hierarchy look like? I don't have experience with layers for example. And while the login panel can go away after the user gets logged in, the other two must remain the same no matter which one of them is visible.
Also, no matter what your answer is, how exactly would the new UIWindow flow look like? How do I attach it instead of the initial one? do they have layers? etc.
Thanks!
as you have said you can only have one uiwindow so you will need 3 views that you can add them manually using add subview to your main window or use the interface builder to make navigation controllers or tab-bar controller etc... which seems a better solution
resources
for basic difference between uiwindow
and uiview see this
for uiview controllers guide
this will be helpful
and here is the interface builder
guide

Multiple Views within one XIB - iPhone SDK

I have been spending time learning how to use the iPhone SDK. I've read "Beginning iPhone Development: Exploring the iPhone SDK" from cover to cover and I've never seen an example of multiple views within one XIB.
To illustrate what I mean, here is a screen shot of a XIB with the simple configuration of what I'm referring to:
alt text http://theopensourceu.com/wp-content/uploads/2009/04/one-xib-multiple-views.png
I figure that there has to be a very specific reason that I've never seen this. In Apple's examples and in all of my readings thus far, multiple XIBs are used with only a single 'view' (and sometimes the Navigation Controller or a Tab Bar Controller, etc). What is the reason for this? Should I avoid multiple views inside a XIB? What are the advantages or disadvantages to to either method?
Thank you in advance
It's a question of memory optimization and loading times. If you put all your views in one XIB, then when your application launches, it has to load the entire XIB into memory and construct all of the objects for all of the controls, and this takes a non-trivial amount of time.
If instead you separate your views into separate XIBs, then your app will start up much faster, because only the XIB containing the initial view will be loaded, and it will also use less memory at first. Then, when the view changes, you can load the XIB containing the new view lazily. This will incur a minor hitch when opening a view for the first time. If you're really trying to optimize memory use, you can also unload the previous view when switching views, but I wouldn't recommend this, as this will incur a hitch every time you switch views, instead of just the first time you switch to any given view.
Following up on the previous answer, there are some times when you would like to load multiple views at the same time. Here's an example: You are displaying a report with multiple pages and you're going to use a UIScrollView to manage them. When the user is done browsing the report, he will close the report which will dismiss the view.
Create a UIScrollView in a XIB along with a UIView for each page you need. Since the UIViews are part of the XIB, they will be loaded into memory together, all at once, when the report is opened. Create two UIViewControllers and use them to display the page being viewed and the one being scrolled to. As the user moves through the pages, re-use the UIViewController on the page being scrolled away from to hold the page being scrolled to.
This will ensure great performance while the user is flipping through the pages. It loads all the pages at once up front into memory. I only uses two UIViewControllers, and it just changes which views are in them and moves them around.
This also has the great benefit of having all of the pages in one XIB. It makes it easier to edit, and quicker to load than separate XIB's. You just have to make sure you have the memory to load all the pages at once. If it's static content (such as in my case) it's a great way to go.
If you're looking for a good example of how to do this, I found this resource to be an excellent starting point:
http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html
This is a warning to anyone trying to implement landscape and portrait with two views in a single XIB (iOS 4 with Xcode 4). The primary disadvantage of having two views in a single XIB–for me–was that you can only connect a single UIOutlet object in a XIB to a single UIOutlet object in a view controller.
So, for example, if you have a XIB with a view for landscape and a view for portrait, and both views contain the same interface objects in different positions (such as a UILabel in landscape and a UILabel in portrait). It is not possible to link the UILabel in your portrait view and the UILabel object in the landscape view to a single UILabel object in the view controller at the same time.
I find this a disappointment, as the iOS UIViewController documentation (iOS 4.3) suggested that I could implement custom landscape and portrait views by switching between two views programmatically as the screen rotates.
After spending quite some time to figure out how to do this, I discovered that it is possible to have two different views attached to a single view controller, but you need to have outlets for both views. For example, in my view controller, I have two UILabel objects (one to connect to a UILabel in the portrait view; one to connect to a UILabel in the landscape view). In my code, every time I update the landscape outlet, I also update the portrait landscape.
Not very elegant, but it works, and as this is for a simple view with one screen, it won't use up too much memory to have have all the UI objects duplicated in the controller and views. I wouldn't create a project that did it that way again, but it was a good enough work-around for that project.
One reason I place multiple views in one xib is because unlike storyboard xibs don't allow placing header and footer in the table view itself. So I create to separate view for header and footer view and assign them in viewDidLoad.