Search code examples
iphonemultiple-views

Question about multiple views in iPhone App Development


Is it possible to create a viewcontroller that could handle 5 views? And is it possible to implement a different button on every view to make a transition to root view?

So my idea of the app is when I load it it takes me to main window, and on that window there will be 5 button that will take me to the 5 views, and after I'm in that view, among other buttons there will be just one button that will take me only to the MainView.

Let's say that some of those 5 views will be Options, Score, Statistics, something like that.

If it is possible to make an app like that using so much views, is it a good approach?


Solution

  • This would be possible, but from what you describe, it does not sound like a good idea. I would suggest instead making a Tab Bar app, and having a separate view controller for each of your 5 views.

    If you do not want to make a tab bar app, you can certainly do what you describe, but I would recommend having a separate view controller instance for each view. You could have your 5 buttons in your main view, and each button could push a modal view with no animation. You could then add whatever transition animation you want. In your modal view, you could have a button that pops the modal view.

    In your main view controller, you would do this:

    - (IBAction)button1Click {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    
        UIViewController *newController = [[UIViewController alloc] initWithNibName:@"View1" bundle:nil];
        [self presentModalViewController:newController animated:NO];
        [newController release];
    
        [UIView commitAnimations];
    
    }
    

    And in your view 1 controller:

    - (IBAction)backToMainClick {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    
        [self dismissModalViewControllerAnimated:NO];
    
        [UIView commitAnimations];
    
    }