tags:

views:

56

answers:

1

This is a method I use to switch display views, based on a string passed (for example you could pass MainMenuViewController to switch views to a new instance of that class):

- (void)displayView:(NSString *)newView
{
    NSLog(@"%@", newView);

    [[currentView view] removeFromSuperview];
    [currentView release];

    UIViewController *newView = [[NSClassFromString(newView) alloc] init];
    [[newView view] setFrame:CGRectMake(0, 0, 320, 460)];
    [self setCurrentView:newView];

    [[self view] addSubview:[currentView view]];
}

I have my application forced into landscape view (.plist and -shouldRotate), but if you look in the code:

[[newView view] setFrame:CGRectMake(0, 0, 320, 460)];

I have to set the frame of the newView to a portrait frame for the view to be displayed correctly - otherwise, for example, a button on the new view can only be pressed in certain parts of the screen (rectangle up the top), unresponsive anywhere else. Even though in all my NIB files they are set to landscape.

A: 

Here is the fixed code: (this is in the 'multi view controller')

[super viewDidLoad];
**[[self view] setFrame:CGRectMake(0, 0, 480, 300)];**

IntroductionViewController *newView = [[IntroductionViewController alloc] init];
[[newView view] setFrame:CGRectMake(0, 0, 480, 300)];
[self setCurrentView:newView];
[[self view] addSubview:[currentView view]];
David Lawson