如何将按钮链接到 Xcode 6 中的操作?

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

How to link a button to an action in Xcode 6?

iosobjective-cxcode

提问by Ethan Humphries

I am trying to create a button, that when it receives the "Touch Up Inside" call, will ring a phone number. However, the action I have declared in my ViewController.h is not showing up in my Connections Inspector, so I cannot connect the code to my button. Within my ViewController.h I have written the line of code:

我正在尝试创建一个按钮,当它收到“Touch Up Inside”电话时,会响起一个电话号码。但是,我在 ViewController.h 中声明的操作没有显示在我的 Connections Inspector 中,因此我无法将代码连接到我的按钮。在我的 ViewController.h 中,我编写了以下代码行:

-(IBAction)makePhoneCall(id)sender;

And I have finished my declaration in my ViewController.m, but it still wont appear in my Connections Inspector.

我已经在 ViewController.m 中完成了我的声明,但它仍然不会出现在我的 Connections Inspector 中。

Any suggestions for help would be greatly appreciated.

任何帮助建议将不胜感激。

回答by Unheilig

What you need is to go to your storyboard, click on the Utilities button on the far right.

您需要的是转到故事板,单击最右侧的“实用程序”按钮。

From there click on your controller; third tab from left you will see "Custom Class", there you need to change the name to the name of the class in which you declare your method.

从那里单击您的控制器;左起第三个选项卡您将看到“自定义类”,您需要将名称更改为您声明方法的类的名称。

See picture:

见图片:

enter image description here

在此处输入图片说明

From then on, try to connect your method again using connection inspector.

从那时起,尝试使用连接检查器再次连接您的方法。

Edit:

编辑:

Adding picture for selecting the view controller in storyboard:

添加用于在故事板中选择视图控制器的图片:

enter image description here

在此处输入图片说明