如何在 Xcode 中查看视图控制器的代码视图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9298599/
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 23:18:59  来源:igfitidea点击:

How see code-view for view controller in Xcode?

iosxcodefunctionuiviewcontrollerviewcontroller

提问by pradope

In my Xcode project, I have several view controllers in my storyboard. How can I see the code for a specific view controller?

在我的 Xcode 项目中,我的故事板中有几个视图控制器。如何查看特定视图控制器的代码?

Because each view controller will need to have different functions from the others. So, where can I write that code?

因为每个视图控制器都需要与其他视图控制器具有不同的功能。那么,我在哪里可以编写该代码?

Thanks!

谢谢!

回答by sch

By default, storyboard will use UIViewController for the view controllers you use.

默认情况下,故事板将使用 UIViewController 作为您使用的视图控制器。

However you can change the class used for the view controller by:

但是,您可以通过以下方式更改用于视图控制器的类:

  1. selecting the view controller (in Interface Builder)
  2. show the identity inspector (View > Utilities > Show identity inspector)
  3. Change the value in Class to "MyOwnViewController"
  1. 选择视图控制器(在 Interface Builder 中)
  2. 显示身份检查器(查看 > 实用工具 > 显示身份检查器)
  3. 将 Class 中的值更改为“MyOwnViewController”

Where "MyOwnViewController" is the name of the UIViewController subclass that you want to use for that view controller.

其中“MyOwnViewController”是您要用于该视图控制器的 UIViewController 子类的名称。

回答by max lau

  1. Select the View Controller you want to see the code
  2. Go to the Assistant editor
  1. 选择你想看代码的View Controller
  2. 转到助理编辑

It's on the upper bar to the right.

它位于右侧的上方栏上。

回答by pradope

The "Show the Assistant editor" venn diagram icon on the top right did it for me. Xcode Version 6.4

右上角的“显示助理编辑器”维恩图图标为我完成了这项工作。Xcode 6.4 版

回答by zaph

You subclass each UIViewControllerto add unique functionality. The implementation of UIViewControlleris private to Apple, the interface is described in it's documentation.

您将每个子类化UIViewController以添加独特的功能。的实现UIViewController是 Apple 私有的,接口在其文档中进行了描述。

回答by Bob

Select the storyboard in the navigator, right click and select 'Open As'. You should see 2 options 'Interface Builder - Storyboard' or 'Source Code' - select the Source Code option should fix your issue.

在导航器中选择故事板,右键单击并选择“打开为”。您应该看到 2 个选项“界面生成器 - 故事板”或“源代码”-选择源代码选项应该可以解决您的问题。