xcode 7.3:无法插入新的插座连接并删除 DerivedData 不起作用

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

xcode 7.3: Could not insert new outlet connection and deleting DerivedData doesnt work

iosxcodeswift

提问by swyx

the most common answer for this questionon SO is 3 years old and the commonly agreed solution (delete DerivedData) doesn't work for me so I have to re ask this question.

关于这个问题最常见的答案是 3 岁,普遍同意的解决方案(删除派生数据)对我不起作用,所以我不得不重新问这个问题。

this is the problem i have, optically looks the same

这是我的问题,光学上看起来一样

I am trying to drag to create an outlet for my tableview.

我正在尝试拖动为我的 tableview 创建一个插座。

as mentioned, deleting DerivedData does nothing for me (but I can see it reindexing). The second most common answer is

如前所述,删除 DerivedData 对我没有任何作用(但我可以看到它正在重新编制索引)。第二个最常见的答案是

Removing(removing reference, not deleting) and then adding the appropriate file(the file of class you want to add the outlet to) is actually enough.

Edit 1 I found that after unchecking (in XCode 6.3.1) I had to wait a few seconds for the Indexing to appear and complete in the project name box. Same for the way backwards. This increased chances to fix the issue in almost all (but not all) cases.

Edit 2 Removing reference means that You do not delete the file completely but just remove it from the project (it still exist in the folder of your project, you add it later).

删除(删除引用,而不是删除)然后添加适当的文件(您要添加插座的类的文件)实际上就足够了。

编辑 1 我发现在取消选中(在 XCode 6.3.1 中)后,我必须等待几秒钟才能在项目名称框中显示并完成索引。向后的方式也是如此。这增加了在几乎所有(但不是所有)情况下解决问题的机会。

Edit 2 Removing reference 意思是你不完全删除文件,只是把它从项目中删除(它仍然存在于你的项目文件夹中,你以后再添加)。

I dont know if this still applies to Xcode 7.3 since I work on storyboard and don't have any .h or .m files to delete or remove references to. If this advice is still valid in xcode 7.3, could you please advise where to click?

我不知道这是否仍然适用于 Xcode 7.3,因为我在 storyboard 上工作并且没有任何 .h 或 .m 文件可以删除或删除引用。如果这个建议在 xcode 7.3 中仍然有效,你能告诉我点击哪里吗?

Other things I have tried that did not work

我尝试过的其他不起作用的事情

  • cleaning project
  • restarting xcode
  • in Terminal: defaults delete com.apple.dt.Xcode
  • in Terminal: defaults write com.apple.dt.XCode IDEIndexDisable 0
  • rewriting the entire project from scratch
  • 清洁工程
  • 重启xcode
  • 在终端: defaults delete com.apple.dt.Xcode
  • 在终端: defaults write com.apple.dt.XCode IDEIndexDisable 0
  • 从头开始重写整个项目

Help a brother out?

帮兄弟解惑?

采纳答案by christian mini

I've found a way to reproduce systematicallythis error in a simply way

我找到了一种以简单的方式系统地重现此错误的方法

  • Drag the azure line on ViewController and leave drag inside the Hint ("Insert Outlet or OutletCollection): The create connection box appear normaly
  • 在 ViewController 上拖动天蓝色线并在 Hint 内拖动(“Insert Outlet or OutletCollection):创建连接框正常显示

enter image description here

在此处输入图片说明

  • Now after click "Connect" button....BUUM! "Could not insert new outlet connection"
  • 现在点击“连接”按钮后......BUUM!“无法插入新的插座连接

enter image description here

在此处输入图片说明

  • Finally try to do the same thing but leaving the drag outside the hint box
  • 最后尝试做同样的事情,但将拖动留在提示框之外

enter image description here

在此处输入图片说明

  • After click "Connect"you will discover that now all work fine!

    Hope this help!

  • 单击“连接”后,您会发现现在一切正常!

    希望这有帮助!

回答by swyx

Hi future xcode n00bs (i hate when the loop isnt closed by the asker!), please refer to @Paulw11's comment. that fixed it for me

嗨,未来的 xcode n00bs(我讨厌提问者没有关闭循环!),请参阅 @Paulw11 的评论。为我修好了

You can just create the IBOutlet manually and then in IB drag from "new referencing outlet" to your view controller object in the left hand panel (you will need to expand this panel first, from your screenshot it is currently hidden) and make the connection. The assistant view is often a bit flakey

您可以手动创建 IBOutlet,然后在 IB 中从“新引用插座”拖动到左侧面板中的视图控制器对象(您需要先展开此面板,从您的屏幕截图中它当前处于隐藏状态)并建立连接. 助手视图通常有点古怪

回答by Julia Wozniak

what worked for me - delete class file (which appeared to be in a "Base project" folder)
- create a new one in the default project folder.

什么对我有用 - 删除类文件(它似乎在“基本项目”文件夹中)
- 在默认项目文件夹中创建一个新文件。

btw I tried deleting derived data before and it there still was the same error.

顺便说一句,我之前尝试删除派生数据,但仍然存在相同的错误。

回答by rleedev

The simple solution for me was to create a new ViewController class and reassign that class to the storyboard. Then I was able to use the IBOutlets via click and drag as usual.

对我来说,简单的解决方案是创建一个新的 ViewController 类并将该类重新分配给故事板。然后我就可以像往常一样通过单击和拖动来使用 IBOutlets。

My issue seemed to be caused by attempting to rename the class. I renamed the file, in code, and reattached it in storyboard. But the IBOutlets seem to have an issue with classes being renamed.

我的问题似乎是由于尝试重命名类引起的。我在代码中重命名了该文件,然后将其重新附加到故事板中。但是 IBOutlets 似乎在重命名类方面存在问题。

回答by Nelson

I tried a lot of options without good results, at the end, i opened terminal and type:

我尝试了很多选择都没有好的结果,最后,我打开终端并输入:

defaults delete com.apple.dt.XCode IDEIndexDisable

默认删除 com.apple.dt.XCode IDEIndexDisable

Then i restarted the mac, and opened Xcode again, it was working now (This even solve autocompleting issues)

然后我重新启动 mac,再次打开 Xcode,它现在可以工作了(这甚至解决了自动完成问题)

回答by guido

None of the above solutions worked for me. (deleting derived data, removing target class file and re-adding it, creating a new target class file and copy and paste the text in there, restarting xcode, restarting mac, clean, clean build folder, or in any combination that I could think of, etc.)

以上解决方案都不适合我。(删除派生数据,删除目标类文件并重新添加它,创建一个新的目标类文件并将文本复制并粘贴到其中,重新启动 xcode,重新启动 mac,清理,清理构建文件夹,或我能想到的任何组合等)

In the end, what did work, was adding a line to the target class (like print("dummy")) and then build the project.

最后,有效的是向目标类(如print("dummy"))添加一行,然后构建项目

I can only guess why. My guess is that none of the other solutions enforced a new compilation of the target-class file. Somehow xcode 'knows' for which classes the code changed. Adding an empty line or comment line didn't work btw. Xcode is 'smart' appearantly and know a new compilation is not required if you add a comment or empty line. It needs to be compilable code. Again... just a guess. Also have no idea why deleting derived data, clean and clean build folder didn't work.

我只能猜测为什么。我的猜测是,其他解决方案都没有强制执行目标类文件的新编译。不知何故,xcode“知道”代码更改了哪些类。顺便说一句,添加空行或注释行不起作用。Xcode 看起来很“聪明”,并且知道如果您添加注释或空行,则不需要新的编译。它需要是可编译的代码。再次......只是一个猜测。也不知道为什么删除派生数据,干净和干净的构建文件夹不起作用。

回答by lukas_o

If this doesn't work to drag the connection from the storyboard or nib, you can do it from the Connections Inspector. Click and drag the '+' sign on 'New Referencing Outlet'.

如果从故事板或笔尖拖动连接不起作用,您可以从连接检查器中进行。单击并拖动“新参考插座”上的“+”号。

Worked for me on xCode 7.3.

在 xCode 7.3 上对我来说有效。

enter image description here

在此处输入图片说明

回答by Raunak

In my case it was another file (say HeaderCell.Swift) that I had accidentally deleted but was part of compile sources. Xcode was not showing the actual problem but was wrongly displaying "Could not insert new outlet connection" for (FooterCell.swift & FooterCell.xib). After I restored the file HeaderCell.Swift, the IBOutlet connection worked fine.

就我而言,它是另一个文件(比如 HeaderCell.Swift),我不小心删除了它,但它是编译源的一部分。Xcode 没有显示实际问题,但错误地显示 (FooterCell.swift & FooterCell.xib) 的“无法插入新的插座连接”。在我恢复文件 HeaderCell.Swift 后,IBOutlet 连接工作正常。