ios Ctrl-从按钮拖动到不起作用的方法。Xcode/界面生成器

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

Ctrl-Drag from button to method not working. Xcode/Interface Builder

objective-ciosxcodeinterface-builder

提问by Dreken105

I am building an iOS app and i have most of the code/GUI built (its a single view app). Now i have the .xib and controller.h file next to each other and I want to associate a button click with a certain action. Everytime I try nothing happens. The UI indictor that I am dragging shows up but it wont let me connect to the method. This happens for all the objects/methods.

我正在构建一个 iOS 应用程序,并且我构建了大部分代码/GUI(它是一个单一视图应用程序)。现在我有 .xib 和 controller.h 文件彼此相邻,我想将按钮单击与某个操作相关联。每次我尝试什么都没有发生。我正在拖动的 UI 指示器出现了,但它不会让我连接到该方法。所有对象/方法都会发生这种情况。

I have an almost identical project that works just fine too!

我有一个几乎相同的项目,它也能正常工作!

回答by jhilgert00

Select your XIB file and then select "Files Owner" which is the yellow cube. In the Utilities Sidebar, select the Icon with the circle and arrow inside of it (which is the "Connections Inspector"). You can then Control + Drag your to your button.

选择您的 XIB 文件,然后选择黄色立方体的“文件所有者”。在实用工具侧栏中,选择内部带有圆圈和箭头的图标(即“连接检查器”)。然后,您可以 Control + 将您的按钮拖到您的按钮上。

//// Edit ////

//// 编辑 ////

After investigating your project... Pretty sure you deleted a storyboard and then added a .xib but didn't set it's class, or link it's view as an outlet.

在调查了你的项目之后......很确定你删除了一个故事板,然后添加了一个 .xib 但没有设置它的类,或者将它的视图链接为一个插座。

To do that:

要做到这一点:

  1. Select the new view (XIB), then selct the main view, and in the identity inspector, set it's class to your custom class name "AVYSViewController."

  2. Switch to the connections inspector and Control + Drag the "view" outlet to the main view in your XIB.

  1. 选择新视图 (XIB),然后选择主视图,并在身份检查器中,将其类设置为您的自定义类名“AVYSViewController”。

  2. 切换到连接检查器和 Control + 将“视图”出口拖动到您的 XIB 中的主视图。

Also, your project was looking for the MainStoryBoard.storyboard file. So get rid of that setting by selecting your project, then selecting your target, and in the "Summary" tab, delete anything in the "Main Storyboard" field.

此外,您的项目正在寻找 MainStoryBoard.storyboard 文件。因此,通过选择您的项目,然后选择您的目标,并在“摘要”选项卡中,删除“主故事板”字段中的任何内容来摆脱该设置。

Note: I checked to see if your project settings were valid before I deleted the storyboard setting and it returned NO errors, so beware of this problem for future projects.

注意:在删除情节提要设置之前,我检查了您的项目设置是否有效,并且没有返回任何错误,因此在以后的项目中要注意这个问题。

回答by DrunkenBeetle

I think i'm reading the same book as you (Big Nerd Ranch's "iOS Programming"). If so then yeah, I had the same issue as you. Admittedly I am using my laptop to vnc through to a mac box to work on xcode, so I thought it was vnc not capturing the keyboard properly, but turns out it wasn't vnc as I could right-click/cntl-click drag on other things.

我想我和你在读同一本书(Big Nerd Ranch 的“iOS 编程”)。如果是这样,那么是的,我和你有同样的问题。不可否认,我正在使用我的笔记本电脑通过 vnc 连接到 mac box 以在 xcode 上工作,所以我认为这是 vnc 没有正确捕获键盘,但事实证明它不是 vnc,因为我可以右键单击/cntl 单击拖动其他事情。

Admittedly again I didn't do much research on why it wasn't working, but in the meantime I just right-clicked on the button, which shows the events that the button emits, then click-dragged the "Touch Up Inside" event and dropped it on the controller/owner, which then displayed the actions/methods to hook the event to. If you look on page 17 (if you are reading the same book) then that is the event that was hooked up.

不可否认,我没有对它为什么不起作用做太多研究,但与此同时,我只是右键单击了按钮,该按钮显示了按钮发出的事件,然后单击并拖动“Touch Up Inside”事件并将其放在控制器/所有者上,然后显示将事件挂钩到的操作/方法。如果您查看第 17 页(如果您正在阅读同一本书),那么这就是相关联的事件。

Sorry if there are any obvious glaring errors with what I just say, have only just started reading this book today after a big lunch.

对不起,如果我刚才说的有任何明显的明显错误,今天刚吃完午饭才开始阅读这本书。

回答by FlowUI. SimpleUITesting.com

I think you should rephrase you question.. It's very confusing. But if i understand what you are saying, you now have the files open side-by-side in the using the assistant editor. The Xib file on the left hand side, the .h file on the right. correct?

我认为你应该重新表述你的问题..这很令人困惑。但是,如果我理解您的意思,您现在可以在使用助手编辑器中并排打开这些文件。左侧是 Xib 文件,右侧是 .h 文件。正确的?

Now you are trying to link the event in the control, to the method you have defined in the .h file. right?

现在您正在尝试将控件中的事件链接到您在 .h 文件中定义的方法。对?

So if you arein fact seeing the methods in the .h file that you want to link to, but the editor is not letting you link to it, then chances are that you have have the xib file side-by-side with the wrong .h file. Are you sure that the .xib file and the .h that are side-by-side are both called controller? controller.h and controller.xib ?

所以,如果你现今所见的.h文件的方法,要链接,但是编辑器不会让你链接到它,然后有机会,你必须有厦门国际银行文件并排侧与错.h 文件。您确定并排的 .xib 文件和 .h 都称为controller吗?controller.h 和 controller.xib ?