Okay, I have read books upon books all with great examples of having multiple view controllers with their own Nibs along with reading the apple docs.
My question is this: All examples show the multiple view being displayed via a toolbar or tab bar. User clicks some button on one of those mentioned, a new view is displayed, (keeping the tab / tool view bar displayed), then they can click another 开发者_JS百科button on the tab/tool bar and go to another view.
Is this the only way it is possible? If I want to have a Main Screen with three buttons in the middle of the screen (Play Game, Rules, High Scores), and when clicked, have it bring up the correct nib file, can this only be done via the tool bar /tab bar? If so, on some apps where it is not present, is this because it is "hidden"?
I know this is probably one of the most basic things to start with, but I can't seem to grasp this.
I have read about views, subviews etc, and seem to be getting more confused as I go on. If I am totally off base here, is there an example out there that would have something like this:
mainViewController, with nib that has3 buttons clicking any button would call another separate view with its own nib. On that view, I could do whatever it wants, and then have a button that would allow me to go back to the mainViewController.
Any help/examples with this is greatly appreciated.
Geo...
You don't need to be using a UINavigationController
to do this...
Here's one way I could think of to do it. Assume the following:
mainMenuViewController
- your view controller that has the 3 buttons
view1ViewController
- the first of your other views
view2ViewController
- the second of your other views
view3ViewController
- the third of your other views
Have your button that calls view1 in mainMenuViewController
create the UIViewController, then remove itself from the window, for example:
YourAppApplicationDelegate *delegate = (YourAppApplicationDelegate*)[[UIApplication sharedApplication] delegate];
[self.view removeFromSuperview];
[delegate.window addSubview:view1ViewController.view];
And you could do the same with the "return to main menu" button in each of those second-level view controllers.
You can go and back between your views using the presentModalViewController / dismissModalViewControllerAnimated method from UIViewController like that for exemple:
- (IBAction)button1IsPressed:(id)sender {
UIViewController *controller1;
[controller1 setDelegate:self];
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:controller1 animated:YES];
[controller1 release];
}
- (void)dismissViewController {
[self dismissModalViewControllerAnimated:YES];
}
And to go back call this function in the controller1:
[self.delegate dismissViewController];
That's just an example, you can make some amelioration.
精彩评论