无法使用故事板以编程方式切换视图? [英] Unable to switch views programmatically using a storyboard?

查看:129
本文介绍了无法使用故事板以编程方式切换视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode 4.2开发基于故事板的应用程序。我是故事板的新手,之前我曾经通过创建一个类的新实例来切换视图:

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];
}

然后:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"theNewView"])
    {
        [[segue destinationViewController] setText:theText];
        [reader presentModalViewController:[segue destinationViewController] animated:YES];
    }
}

我确保链接制作精良且调用 prepareforsegue 方法,但即使使用此代码,也没有加载新视图?

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?

推荐答案

不要在 prepareForSeque 方法中调用 presentModalViewController - 此方法用于传递信息到新视图控制器。

Don't call presentModalViewController in your prepareForSeque method - this method is for passing information to the new view controller.

请参阅发布

有用的学习用于开始使用故事板的博客帖子

这篇关于无法使用故事板以编程方式切换视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆