gpt4 book ai didi

objective-c - 如何将新类文件关联为特定场景的 View Controller ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:15 25 4
gpt4 key购买 nike

好的,我会尽量让这个简短而有趣。我最近创建了我的第一个 iOS 应用程序,在我的应用程序中,我决定通过在创建项目时选中复选框来走 Storyboard路线。附带一提,我最近刚开始使用 Xcode 进行开发,请记住这一点。所以我从设计我的应用程序的 GUI 元素开始,在不知不觉中,我的 Storyboard文件和一个 View Controller 中有 8 个场景。不用说, View Controller 已经填充了来自不同场景的代码,因此很难理解 View Controller 中的内容。本着 OO 设计原则的精神,我认为为每个场景创建一个单独的 View Controller 是个好主意。所以我为项目创建了一些类文件。当我尝试将新创建的类文件与场景相关联时,我的计算机只会发出哔哔声。我试图通过在 Storyboard/Interface Builder View 中选择场景,然后在右侧显示 Utilities Pane ,然后选择 Identity Inspector< 将新创建的类文件关联到场景/em> 在 Utilities Pane 的顶部,然后将自定义类设置为我新创建的类文件,但是当我键入类的名称并按 enter 键时,我只听到一声哔声。

如果有人有任何见解或知道解释此过程的教程,请发布。我尝试这样做的部分原因是为了代码可读性、更好的代码管理以及更好的应用程序代码结构。我遇到了这个 stack thread解释我正在谈论的一些内容。

此外,如果这有助于说明问题,这里还有一张我的项目的图片。 enter image description here

最佳答案

您需要考虑 Controller 的父类,例如 UIViewController。为此,您必须检查 .h 文件和您的 xib/nib 文件。

我。在您的 .h 文件中,您将看到:

@interface ViewControllerWelcome : NSObject

将 'NSObject' 更改为 'UIViewController' - 这意味着 ViewControllerWelcome 有一个父类 UIViewController .

二。在你的 nib/xib 文件中:

1. Click on the controller that you are going to set from the storyboard.
2. Go to interface builder and click the "Identity Inspector" (third item from the left) from the Utilities panel.
3. You need to specifically set each controller's name (eg. ViewControllerWelcome)

对 Storyboard中的所有 Controller 执行这些操作。

这里是您可以阅读的关于 ViewControllers and Storyboards 的内容.

关于objective-c - 如何将新类文件关联为特定场景的 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10988672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com