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.
Related
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.
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.
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
I've got a SplitView template project.
I want to change DetailView on user selecting item in RootViewController.
In fact I can't just change what's inside that view (DetailView) like it's done in the template (when you check "use core data storage" on creating project).
I want to switch between whole views.
I've tried that:
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.detailViewController setView:curretnDetailViewController.view];
appDelegate.detailViewController = currentDetailViewController;
By the way I don't understand why do I need line#2 (..setView:..)? Why assigning detailViewController (line#3) is not enough? - Code looks awful=(
But anyway that doesn't work exactly as I want. Everything except detailView disappears. Like I've changed the main view, not just DetailViewController's
I guess I should change something in splitViewController but didn't find out what=(
Thanks for your attention.
I too had your questions about a week ago and I too got little help in this forum. I hope I can change that for you.
First did you know apple has a Multi Detail View example? It is here Apple Examples
You have to understand what a splitviewcontroller is to get the idea of what Apple is doing. Think of the splitview controller as a container within your device window. This container has 2 compartments, a thin left hand side a bigger right hand side. Now to change over either side you have to replace this compartment with another compartment of similar size and nature. You cannot put in there a compartment that does not fit or that does something fancy cause it will simply not fit.
In technical talk find this below code in the example. The splitview controller has an array of 2 views and you can change the views in this array. Thus in this array is 2 views the left is called navigationcontroller and the right is detailviewcontroller. If you alloc and initiate a view and add it to either of these two then this view will replace the current view in the splitviewcontroller.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
Now to your second part to your question - which I think is from the left hand side you want to be able to always be able to choose something and be able to change the right hand side....am I right?
I have read three different ways of doing this and not seen anyone who says one is better than the other.
set up a notification - whereby when you click on something on the left a noticiation is sent to the right hand side.
when you start with the bottom or root view of the left hand side you will have a reference to the right hand side, if you add subviews etc to the left hand side you always pass along a reference to the right hand side.
The way I did it was to set up a protocol in the appdelegate or in the rootview delegate, then on a view that I want to talk to the right hand side it uses this protocol and my right hand side implements this protocol. This last one I learnt as it is a preferred method of getting modal views to talk to other views.
I am not an expert so I have not added code for each of the 3 choices above, what I suggest is that you do a little bit of googling for the topics and you will see examples. If you get really stuck on one let me know and I will try to find again with google the examples that I have found in the past. The least complicated I think is No.1.
I hope this get you going in the right direction.
I'm currently using UISplitViewController as my app's rootViewController. To present progress dialogs I use presentModalViewController, but for the one and other reason I'm not entirely happy with it and want to do my own modal thing.
If one of my modal views is supposed to be shown, I want to add another subview to my app's main window. This subview is going to be managed by its own UIViewController subclass to make it rotate properly and do all the stuff I need.
Is this design aproach okay or will I run into issues with UISplitViewController (it is very special in so many ways and seems to be offended easily if not treaten right! :-))?
Is it a problem to have two UIViewControllers next to each other?
Please don't discuss "why don't you use presentModalViewController then?".
You may be ok with UISplitViewController if you do it properly, as presentModalViewController does something similar.
One alternative you should look into is UIPopoverController and the UIViewController's modalIfPopover property.
Also, you say you aren't happy with presentModalViewController and perhaps if you say what was wrong with it we can help you work around whatever issues you have with it. This is the exact case that it seems to be meant for.