Couple of questions about iPad dev (from iPhone) - objective-c

I am starting to develop an iPad app I have a couple of questions:
For UISplitViewController, how do I change the detail view controller (the one on the right with the controller on the left hand side)? Or do I need to have a Navigation Controller and continuously push view controllers?.
I have a UITableViewCell that's designed for landscape mode. Do I have to setup a separate one for portrait mode?
Is there a way I can zoom out in Interface builder so I can see the entire iPad layout (I am using XCode 4.0.2)
Thanks!

 1. You can change the two controllers by changing the viewControllers property of your UISplitViewController. If you want to keep the one on the left, you could do
[splitVC setViewControllers:[NSArray arrayWithObjects:[splitVC.viewControllers objectAtIndex:0], myNewViewController, nil]];
Though I believe that won't animate the transition. For this, you could use a classical view controller as your right-hand view, and do the transitions inside of it.
 2. No need to do a separate design if you've set your subviews’ AutoresizingMasks appropriately. See the documentations on this, it's quite handy for this kind of situation.
 3. Dunno, I have a huge monitor, I'll leave this one to others :p

Related

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 menu/design

Relevant Data:
I'm making a simple game, using OpenglES. The game itself is done, however I would like to have a main menu as well as some other screens designed in IB. So far I have a death/score screen that is displayed with a simple modelviewcontroller.
I haven't done a ton with GUI building or much programming on the platform outside of C code (posix sockets) and some examples from some books. So I'm not sure how I would go about having lots of views- usually I just use a model view, and it's gotten me along just fine so far. However I don't think that would be the best route here.
Situation:
I have a view controller that shows my main menu- the main menu branches off to the main game, a settings screen, and a high score screen. The main game is made in opengl, and I haven't made the settings view yet, but it likely will be as well. How should I switch between the views? Presenting the main view from the app delegate is as simple as setting the root view controller = newly created view controller, should I do the same thing here? If I do that can I remove the resources from the menu view controller?
Sorry if this is an extremely simple question, I just don't quite get the process.
I'm not entirely sure what you want to do, but an easy way to show a new view controller is:
SecondViewController *aSecondViewController = [[SecondViewController alloc]
initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:aSecondViewController animated:YES];
I hope that helps.
How should I switch between the views?
In the vast majority of cases, you should be using a UINavigationController. Your initial controller would be the main menu. When you want to go into a particular section of your application, you push a new view controller onto the stack. When you want to come back out, you pop it off the stack.
Besides navigation and presenting modally that others have mentioned, another option is to swap out views. May or may not fit your app's flow but wanted to point out another option for you to consider
Best practice for switching iPhone views?
If you are already limiting the game to iOS 5 for some other reason you should look into UIStoryboard. If you don't currently require iOS5 the "simplest" way is to use table views, but that isn't a very "gamey" UI.

iOS Multiview App

I am trying to build a multiview app i.e. based on some gestures, new views are shown, removed etc.
I have found 3 ways to do so -
[self.view insertSubview:newViewController.view atIndex:3];
Using UINavigationController
Finally using modalViewController - [self presentModalViewController:newViewController animated:YES];
First off, in second method, can I use this controller without UINavigationTabBar? I have a set of custom UIView objects which I want to push & pop from Screen. I dont want the ugly Apple's NavigationBar at top (or bottom). I will provide custom buttons based on which [self.navigationController popViewControllerAnimated] should occur. Can this be possible?
Also, Which of these techniques is best? In terms of usage & code maintenance, memory usage etc.
In terms of usage & code maintenance, memory usage etc., there's little doubt that UINavigationController is the best fit. It's been optimized for exactly the sort of thing you're doing. And because you push and pop UIViewControllers from it (not just UIViews), views that are not currently displayed on screen can be automatically released to free up memory by the OS.
Can you use a navigation view without the bar across the top? I think maybe you should RTFM. Specifically, -setNavigationBarHidden:animated:
That said, UINavigationController is not particularly flexible at doing things it wasn't designed to do. In particular, it's opinionated about the transitions it uses to animate between view controllers on its stack.
You might have some luck pushing and popping sans animation (by passing NO to the animated: parameter of those methods), and having a delegate set up to handle -navigationController:willShowViewController:animated:. You could in theory add a CATransition to the root view's animations there. But anything much more complicated than that (a view that tracks your finger while sliding on to the screen, etc.) and you'll probably have to write your own controller and manage your own views.
But you should still read Apple's View Controller Programming Guide for iOS and the NSNavigationManager specs until you grok them in their fullness. It'd be hard to find a better pattern to base your design around.
Second one UINavigationController. And yes you can use your custom navigation bar.

How can I do an animated switch to UISplitView?

I have looked at the sample generated by xcode when creating a new UISplitView app on the iPad along with countless other tutorials and the documentation from the apple developer site. I have not seen an example where the UISplitView used was not the root of the application. Is this even possible?
What I am trying to accomplish: I have a UITableView to start out and once an item in the list is selected I would like to display a splitview with two different sets of information that is based on the item that was selected.
I curious if this type of implementation is even possible, or just frowned upon, and why. If it is possible, how would I go about implementing and hooking up a UISplitView to behave in this way?
Edit: I'm updating this with what I have. I can now switch to my UISplitView, though the transition is not animated. What is the way to correctly switch to a UISplitView so the transition is animated?
Code for switching right now:
[appDelegate.window addSubview:appDelegate.splitViewController.view];
appDelegate.window.rootViewController = appDelegate.splitViewController;
EDIT 2: In hopes of bumping this back up so more people see it, I have managed to switch from my navigationController to my splitViewController, but when I add the button to be able to navigate back, nothing I do makes a difference and I seem to be locked in. I tried reverse mirroring the code to switch to the splitViewController, but that had no affect, and I am completely out of ideas. Can anyone shed some light on this?
You should always use SplitViewController as a rootViewController: Split view controller must be root view controller
There may be some hacks around it, but when Apple have a strong recommendation and design guidance, I suggest to try to re-think your design before going against the platform -it should save you effort in the long term.
I recommend using the MGSplitViewController, it also works as a non-rootViewController, even nested into an another MGSplitViewController, and there's i.e. a one-liner for the animation to blend in the Master-View, if that is what you want.
In your UITableView didSelectRowAtIndexPath method you would have something like:
UISplitViewController *mySplitView = [[UISplitViewController alloc] init];
[self.navigationController pushViewController:mySplitView animated:YES];
[mySplitView release];
Probably you'll want to subclass UISplitViewController just like you would other view controllers and set in there the master and detail views and so on.

pushViewController and Navigation Applications?

Why do Navigation Applications use pushViewController instead of presentModalViewController like all the other apps? How can a Navigation Application be modified to use presentModalViewController instead? Would it be sub-optimal to do so? Why?
Navigation view controllers and modal view controllers are there for different purposes. The first is used for display hierarchical nested contents. While you request more detailed info about an item, you go deeper in the hierarch pushing more detailed views over the stack.
The modal view is there for displaing only one view over the current. Its usefull for stuff like an info button for your app.
Your question is a little bit like asking why UISplitViewControllers use two controllers and lay their views out side-by-side. That is, UINavigationControllers use pushViewController: to manage their stack of UIViewController instances because that's how Apple decided UINavigationControllers should work. When animated into view, pushed views will slide in from the right and old views slide in from the left when a view is popped.
ANY instance of a UIViewController can use presentModalViewController to display the view of another UIViewController over top of it's own view in a manner which prevents the user from interacting with the view underneath. Depending on the device (iPhone, iPad) you have various options for the visual appearance of the newly presented view and the animation used to bring it into view.
There's nothing stopping you from writing an application that just keeps having one view bring up the next view using presentModalViewController but there'd be no reason to use a UINavigationController to do so. I've never checked if there was a meaningful difference in memory consumption or any other thing you could measure to judge whether doing so is "sub-optimal" from a technical perspective, but it's certainly not the norm so might be sub-optimal from the user experience perspective. Whether that is true or not for your app depends on whether users seem to think the interaction makes sense to them.
Navigation view controllers uses the concept of Stack.Your navigation is stored in stack that's why you can push & pop the View which shows that you can use them for the detail view ....making a hierarchy of views
whereas modal view controllers shows only one view at a time......this is generally used for new flow in app.