Xcode Interface Builder - 删除/重命名错误连接的 IBoutlets / IBactions 的“正确”方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24523086/
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
Xcode Interface Builder - "correct" way to delete/rename miswired IBoutlets / IBactions
提问by dave_the_dev
I am new to Xcode, working through Swift, so I'm not sure if what I am decribing is actually a bug.
我是 Xcode 的新手,正在使用 Swift,所以我不确定我所描述的是否实际上是一个错误。
When using interface builder and the assistant editor, I can create lables, buttons etc, and create Outlets and Action in the code with a control-drag.
使用界面构建器和辅助编辑器时,我可以创建标签、按钮等,并通过控制拖动在代码中创建 Outlets 和 Action。
So long as I am perfect, no problem. But I seem to run into problems if, for example, I make a mispelling of the object name. Or, I choose outlet instead of action. I can't seem to find a way to make a correction that does't seem to totally screw up the IDE. Even if I delete the object in the IB and the code, it seems to leave problems behind when I build. Or, if I try to delete the line in code and re-drag it, a new line of code is created, but the object seems to now reference the new name, and the old, now missing name.
只要我是完美的,没问题。但是,例如,如果我拼错了对象名称,我似乎会遇到问题。或者,我选择出口而不是行动。我似乎无法找到一种方法来进行更正,但似乎不会完全搞砸 IDE。即使我删除了 IB 中的对象和代码,它似乎在我构建时留下了问题。或者,如果我尝试删除代码中的该行并重新拖动它,则会创建一行新代码,但该对象现在似乎引用了新名称和旧的、现在丢失的名称。
Again, I am working with Swift --- Since I don't use/know Objective-C I don't know if there is a similar behavior using that language.
同样,我正在使用 Swift --- 因为我不使用/不知道 Objective-C,所以我不知道使用该语言是否有类似的行为。
Appreciate any pointers. (Other than don't use the Interface builder / storyboards / Swift.)
感谢任何指针。(除了不要使用界面构建器/故事板/Swift。)
回答by user3386109
Use the Connections inspector to break the connection. Then you can modify/delete the object and/or the code without having to worry.
使用连接检查器断开连接。然后您可以修改/删除对象和/或代码而不必担心。
回答by Suragch
The accepted answer is fine, but there are a few ways to do the same thing.
接受的答案很好,但有几种方法可以做同样的事情。
Method One
方法一
Right click the view in the storyboard and then click the little x by the referencing outlet.
右键单击情节提要中的视图,然后单击引用出口旁边的小 x。
Method Two
方法二
Right click the view name in the Document Outline. Then click the little x by the referencing outlet.
右键单击文档大纲中的视图名称。然后单击参考出口旁边的小 x。
Method Three
方法三
Select the view on the storyboard and then click the Connections Inspector. Then you can click the little x to remove an outlet reference.
选择情节提要上的视图,然后单击连接检查器。然后您可以单击小 x 以删除插座参考。
Extra References in Code
代码中的额外引用
If you are getting outlet connections in code that you didn't add yourself see this answer.
如果您在没有自己添加的代码中获得插座连接,请参阅此答案。