user964627
user964627

Reputation: 665

Storyboard and Switch Views?

I have an iPad app that uses the storyboard board feature and then I have a separate .xib file for another view. I can switch to the separate view and its fine:

-(IBAction)SecondView:(id)sender{

    SecondView *Second = [[SecondView alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:Second animated:NO];

}

But when I am in the Second View and try going back I do everything the same just with the first view controller, but It just goes to a black screen:

-(IBAction)FirstView:(id)sender{

    FirstView *First = [[FirstView alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:First animated:NO];

}

What do you guys think? Am I doing something wrong? What is the best way to switch views?

Upvotes: 2

Views: 5204

Answers (2)

amattn
amattn

Reputation: 10065

initWithNibName:bundle is for loading nib or xib files.

If you are loading from a storyboard, you need to use

    FirstView *First= [self.storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];

IDENTIFIER is defined in your storyboard, it's in the Utilities, Attributes Inspector on the right side.

HOWEVER your real problem is that you shouldn't be loading from the storyboard at all. you should just be calling

[self dismissModalViewControllerAnimated:YES];

That call will clean up the presentModalViewController:animated: that you used to put the modal view controller up in the first place.

Upvotes: 5

rob mayoff
rob mayoff

Reputation: 385590

You presented SecondView using presentModalViewController:animated:, so you need to dismiss it using dismissModalViewControllerAnimated:.

- (IBAction)FirstView:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 0

Related Questions