Xcode:如何在 iOS 5 中创建新视图并设置其控制器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8262733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:32:54  来源:igfitidea点击:

Xcode: How to make new views and set their controller in iOS 5?

iosxcodeios5xcode4.2

提问by Jon Cox

In Xcode, making an iOS 5 app, I have one view in the StoryBoard and I have a method in its controller class - which if invoked (happens when return is pressed on keyboard) needs to move the app to another screen view.

在 Xcode 中,制作一个 iOS 5 应用程序,我在 StoryBoard 中有一个视图,我在它的控制器类中有一个方法 - 如果调用(在键盘上按下返回时发生)需要将应用程序移动到另一个屏幕视图。

However I am struggling to get my head around exactly how to create another view for my app. I know that if I go to MainStoryboard.storyboard I can drag a View Controllerobject out onto it, but I don't understand what this is actually making.

但是,我正在努力弄清楚如何为我的应用程序创建另一个视图。我知道如果我去 MainStoryboard.storyboard 我可以将一个View Controller对象拖到它上面,但我不明白这实际上是什么。

It seems to make a “View Controller Scene” in the Document Outline panel, but I don't entirely understand how to set its controller class. Am I even vaguely close to the correct way of making new views for an app?

它似乎在文档大纲面板中制作了一个“视图控制器场景”,但我不完全了解如何设置其控制器类。我什至模糊地接近为应用程序创建新视图的正确方法吗?

Also I can use a button to segue into this new view controller (by control + drag), but I'm not sure how I'd do this in code (such as within the method mentioned above).

我也可以使用一个按钮进入这个新的视图控制器(通过控制 + 拖动),但我不确定如何在代码中做到这一点(例如在上面提到的方法中)。

Hopefully you'll be able to make sense to me how to make views and move between them. Any help would be greatly appreciated :-)

希望你能理解我如何制作视图并在它们之间移动。任何帮助将不胜感激 :-)

回答by Scott Sherwood

To set the class of a view controller you should do this in the identity inspector in interface builder. This will let you select your custom view controller class. To make a view transition to another view by connecting a segue you should add something like a button and right click and drag out a segue across to the view controller you want to transition too you will then be presented with a popup which lets you specify the type of transition e.g modal push etc.

要设置视图控制器的类,您应该在界面构建器的身份检查器中执行此操作。这将让您选择自定义视图控制器类。要通过连接 segue 将视图转换到另一个视图,您应该添加类似按钮的东西,然后右键单击并将 segue 拖到要转换的视图控制器上,然后您将看到一个弹出窗口,让您指定转换类型,例如模态推送等。

For more on this check out my tutorial that should really help you here.

有关这方面的检查出我的教程,应该真正帮助你在这里