iOS Multiview App - objective-c

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.

Related

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.

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.

Couple of questions about iPad dev (from iPhone)

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

Should one use UIViewController in scenarios without UINavigationController?

Summary
From a conceptual point of view, should one be working with UIViewController subclasses and their Nibs, even if you're not using the UINavigationController?
Scenario
The application I'm trying to develop has no UINavigationController. I'm mostly looking at elements in one particular UIScrollView implementation, and if there's at all a 'next level of navigation', it merely alters the appearance of a small element to show more details. The detail views of the elements (different elements spawn different views) are laid out in Interface Builder, for which I opted to create new UIViewController subclasses with corresponding XIB files.
Doubt
While exploring the different ways I could have these instances animate into view, I come across a lot of solutions using the UINavigationController. The UIViewController itself already seems to be geared towards the synergy. There's a self.navigationController, and lot's of examples online of how to push and pop with and without animation.
Question
So what I'm wondering right now is "did I do the right thing?" Googling an answer to that question only brought me to more specific implementation examples, so I decided to post this.
Should I have restrained myself in using XCode's "new file" template for UIViewController subclasses with XIB? Or should I have implemented a UINavigationController in my app, even if there's no screenfulls of navigation going on?
I'd be much obliged for enlightenment.
Cheers,
Eric-Paul.
UIViewController is a useful tool. It offers memory management things, anchor points for interface rotation and lots more. If needed, they can be pushed to a navigation controller (if not now, maybe later), could be a page of a tab bar controller, or behave well in popovers on iPad.
They come cheap and I don't see a reason not to use them. And your code needs to go somewhere anyway. Don't flood the application delegate or the view.

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.