Unable to switch views programmatically using a storyboard?

空扰寡人 提交于 2020-01-03 04:56:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!