xcode 将 .xib 中的对象连接到现有的 IBAction

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

Connect object in .xib to existing IBAction

iphoneiosxcodeinterface-builderibaction

提问by LKS

I am quite new to iOS Programming.

我对 iOS 编程很陌生。

This is my question:

这是我的问题:

I want to connect a new object to an existing IBAction method. For example, I want to buttons to perform the same function.

我想将一个新对象连接到现有的 IBAction 方法。例如,我想按钮执行相同的功能。

But when I "control-drag" it, it will always ask me to insert as a new method. How can I add to the existing one instead of creating a new one?

但是当我“控制拖动”它时,它总是会要求我作为新方法插入。如何添加到现有的而不是创建一个新的?

Snapshot in XCode Snapshot in XCode

XCode 中的快照 XCode 中的快照

回答by tipycalFlow

In your xibeditor, you can see the File's Owner. Just right click the button to see the black popup as shown in the image below. Then drag the emptydot to the File's Ownertab and release the drag action. You'll see a popup of all existing IBActions. Select the one you want and it'll be added as a selector to your button. You can do this for as many buttons as you want.

在您的xib编辑器中,您可以看到File's Owner. 只需右键单击该按钮即可看到如下图所示的黑色弹出窗口。然后将点拖动到File's Owner选项卡并释放拖动动作。您将看到所有现有IBActions的弹出窗口。选择您想要的一个,它将作为选择器添加到您的按钮中。您可以根据需要对任意数量的按钮执行此操作。

enter image description here

在此处输入图片说明