xcode 有没有办法在没有 Ctrl-Drag 的情况下在 Interface Builder 中设置引用出口

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

Is there a way to set referencing outlet in Interface Builder without Ctrl-Drag

xcodeinterface-builderxcode4.3

提问by Krease

So I'm just trying to create a very simple app for demo purposes here:

所以我只是想在这里创建一个非常简单的应用程序用于演示目的:

  • Created a Single View Application, using storyboards
  • Added a UIView to the storyboard
  • Added the following code to my controller's header file:

    @property (weak, nonatomic) IBOutlet UIView *myView;
    
  • 使用故事板创建了一个单一视图应用程序
  • 向故事板添加了一个 UIView
  • 将以下代码添加到我的控制器的头文件中:

    @property (weak, nonatomic) IBOutlet UIView *myView;
    

Now, I understand that I can link the UIView to the controller by:

现在,我知道我可以通过以下方式将 UIView 链接到控制器:

  • arranging my code such that the header file is next to the storyboard
  • holding down Ctrl key and dragging it to the property in the header file
  • 安排我的代码,使头文件在故事板旁边
  • 按住Ctrl键拖动到头文件中的属性

My question is this: can I do this withoutCtrl-drag? And if so, how?

我的问题是:我可以在按住 Ctrl 键的情况下执行此操作吗?如果是这样,如何?

More specifically - it's annoying to have to put both my header file and storyboard on screen at the same time, and it seems there should be a way to make this connection without doing so.

更具体地说 - 必须同时将我的头文件和故事板放在屏幕上很烦人,而且似乎应该有一种方法可以在不这样做的情况下建立这种联系。

I also understand that I can manually place the view by creating it inside my controller's viewDidLoad function, but I'd really like to use the interface builder to simplify / visualize things.

我也明白我可以通过在控制器的 viewDidLoad 函数中创建它来手动放置视图,但我真的很想使用界面构建器来简化/可视化事物。

Edit:Is the answer to my question affected whether I use storyboards or xib/nib files? (I'd switch to use the one where it works)

编辑:我的问题的答案是否会影响我使用故事板或 xib/nib 文件?(我会切换到使用它工作的地方)

采纳答案by Novakedy

In addition to Dima's answer, you can just as well use the Connection inspector in the Utilities pane

除了 Dima 的回答之外,您还可以使用“实用工具”窗格中的“连接”检查器

Connection Inspector

连接检查器

回答by Dima

you should be able to right click the element, and drag the "referencing outlet" item to the view's "File's Owner" in interface builder. There, it will give you a list of all available IBOutlets (matching the object's type).

您应该能够右键单击该元素,然后将“引用插座”项拖到界面构建器中视图的“文件所有者”。在那里,它将为您提供所有可用 IBOutlets 的列表(匹配对象的类型)。