ios 如何删除插座的所有引用

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

how to remove all references for outlet

iosobjective-cxcode

提问by pbd

I accidently set event for command button as "outlet" than "action". Due to auto-drag feature, xcode generated references in applicationDelegate and .h and .m files. I removed the entry from .h and .m files but simulator wont run because it is still looking for that missing reference. I could not find that outlet referred anywhere. I am fairly new to iOS programming. Can anyone suggest a solution for this?

我不小心将命令按钮的事件设置为“出口”而不是“动作”。由于自动拖动功能,xcode 在 applicationDelegate 和 .h 和 .m 文件中生成了引用。我从 .h 和 .m 文件中删除了条目,但模拟器无法运行,因为它仍在寻找丢失的参考。我找不到任何地方提到的那个插座。我对 iOS 编程相当陌生。任何人都可以为此提出解决方案吗?

回答by Mick MacCallum

You have to unlink the outlet from the item in interface builder. Select the UI element that you linked the outlet to and then remove it in the "Connections Inspector".

您必须从界面构建器中的项目取消插座的链接。选择您将插座链接到的 UI 元素,然后在“连接检查器”中将其删除。

enter image description here

在此处输入图片说明

Click the little "x" ^^^

点击小“x”^^^

回答by Suragch

I think there are two different reasons that people may come here wondering how to get rid of an unwanted Outlet reference.

我认为人们来到这里想知道如何摆脱不需要的 Outlet 引用有两个不同的原因。

  1. Created an unwanted outlet while using the Interface Builder.
  2. Copied some Outlet code from another projects View Controller.
  1. 使用界面生成器时创建了不需要的插座。
  2. 从另一个项目 View Controller 复制了一些 Outlet 代码。

Both reasons are fairly easy to solve.

这两个原因是很容易解决的。

Unwanted Outlet in IB

IB中不需要的出口

Method One

方法一

Right click the view in the storyboard and then click the little x by the referencing outlet.

右键单击情节提要中的视图,然后单击引用出口旁边的小 x。

enter image description here

在此处输入图片说明

Method Two

方法二

Right click the view name in the Document Outline. Then click the little x by the referencing outlet.

右键单击文档大纲中的视图名称。然后单击参考出口旁边的小 x。

enter image description here

在此处输入图片说明

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 以删除插座参考。

enter image description here

在此处输入图片说明

Unwanted Reference in Code

代码中不需要的引用

If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets!

如果您将视图控制器代码从一个项目复制到另一个项目,您会注意到插座发生了一件奇怪的事情。它引用了第一个项目的视图,而您从未连接过任何插座!

enter image description here

在此处输入图片说明

If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.

如果您左键单击小圆圈并单击参考链接,您甚至会被带到另一个项目中的故事板视图。试图弄清楚如何摆脱这个引用可能会让你发疯。

Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Use the methods in part one of this answer to see if a view in your current project has a referencing outlet or not.

好吧,好消息是你真的没有什么需要解决的。您没有复制一些深入、难以找到的参考链接。Xcode 只是感到困惑,因为两个项目中的视图控制器和插座名称相同。基本上只是忽略那个小圆圈所说的。您可以关闭第一个项目,Xcode 最终会解决问题。使用本答案第一部分中的方法查看当前项目中的视图是否具有引用出口。

No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior. The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore it.

无需删除派生数据。反正这也解决不了问题。只需再次尝试同时打开两个项目,您就会得到相同的奇怪行为。我想出来的方法是分别创建两个新项目,它们具有同名的视图控制器和同名的引用出口。我从来没有复制过任何东西,但 Xcode 显示一个正在引用另一个。就像我说的,忽略它。

回答by lnafziger

It will be listed in the storyboard/xib as well, on the command button outlets.

它也将列在故事板/xib 中,在命令按钮出口上。

Delete it from there as well, and you should be good.

也从那里删除它,你应该很好。