问题
I am developing a storyboard-based application, using XCode 4.2. I'm new to storyboards, before that I used to switch views by creating a new instance of a class like this:
if (x==1)
{
theClass *theView ;
theView= [[theClass alloc] initWithNibName:nil bundle:nil];
[theView setText:theText];
[reader presentModalViewController:theClass animated:YES]; //where reader is an instance of the ZBar library
}
With storyboards, here is the code I am trying:
if (x==1)
{
[self performSegueWithIdentifier: @"theNewView" sender: self];
}
then:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"theNewView"])
{
[[segue destinationViewController] setText:theText];
[reader presentModalViewController:[segue destinationViewController] animated:YES];
}
}
I made sure that the links are well made and that the prepareforsegue
method is called, but even with this code, the new view is not being loaded?
回答1:
Don't call presentModalViewController
in your prepareForSeque
method - this method is for passing information to the new view controller.
See post.
Useful learning weblog post, for getting started with a storyboard.
来源:https://stackoverflow.com/questions/8897418/unable-to-switch-views-programmatically-using-a-storyboard