问题描述
我正在构建一个iOS应用程序,我已经构建了大部分代码/ GUI(它是一个单一的视图应用程序)。现在我将.xib和controller.h文件放在一起,我希望将按钮单击与某个操作相关联。我每次尝试都没有任何反应。我正在拖动的UI指示器显示但它不会让我连接到该方法。对于所有对象/方法都会发生这种情况。
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.
我有一个几乎相同的项目也可以正常工作!
I have an almost identical project that works just fine too!
推荐答案
选择您的XIB文件,然后选择文件所有者,这是黄色立方体。
在Utilities侧栏中,选择带有圆圈和箭头的Icon(这是Connections Inspector)。
然后你可以控制+拖动你的按钮。
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.
////编辑////
//// Edit ////
调查你的项目后......
很确定你删除了一个故事板,然后添加了一个.xib,但没有设置它的类,或者将它的视图作为插座链接。
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),然后选择主视图,并在身份检查器中将其类设置为您的自定义类名AVYSViewController。
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."
切换到连接检查器和Control +将view插座拖到XIB中的主视图中。
Switch to the connections inspector and Control + Drag the "view" outlet to the main view in your XIB.
此外,您的项目正在寻找MainStoryBoard.storyboard文件。因此,通过选择项目然后选择目标来摆脱该设置,并在摘要选项卡中删除主要故事板字段中的任何内容。
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.
注意:我在删除故事板设置之前检查了您的项目设置是否有效,并且它返回了NO错误,因此请注意未来项目中的此问题。
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.
这篇关于Ctrl-从按钮拖动到方法不起作用。 Xcode / Interface Builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!