故事板和切换视图? [英] Storyboard and Switch Views?

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

问题描述

我有一个使用情节提要板功能的iPad应用程序,然后我有一个单独的.xib文件用于另一个视图。我可以切换到单独的视图及其罚款:

-(IBAction)SecondView:(id)sender{

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

}

但当我在第二个视图中时尝试回去我只用第一个视图控制器做同样的事情,但它只是一个黑屏:

-(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?

推荐答案

initWithNibName:bundle 用于加载nib或xib文件。

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 在故事板中定义,它是在公用事业,右侧的属性检查器中。

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

该调用将清理 presentModalViewController:animated:你曾经把模态视图控制器放在首位。

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

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

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