重命名类导致 IBOutlet 连接失败 [英] Renaming class causes IBOutlet connection to fail
问题描述
我重命名了一个类,该类碰巧与故事板文件中名为 mainLabel 的标签有一个插座连接.当我运行我的程序时,它崩溃并给我一个错误:这个类不是键 mainLabel 的键值编码兼容".
其他 SO 答案表明这是由插座连接不良引起的,因此我删除了连接并删除了任何丢失的一端.在我的代码中尝试将标签重新连接到插座时,出现错误 无法插入新的插座连接: 找不到名为 CourseTableViewCell 的类的任何信息>
其他 SO 答案提供了我尝试过但没有奏效的解决方案,包括:
- 删除对文件的引用并重新添加
- 清理项目
- 删除派生数据文件夹
- 删除标签并重新添加
- 从代码拖到故事板,而不是相反
我确保在身份检查器中的自定义类"下列出了正确的文件名.如果有人有任何其他想法,请告诉我!
如有必要,我可以提供更多信息.
以下步骤是您从和对象中查找现有 IBOutlet/IBAction 所需要做的.是label
、button
等等.以及如何删除它.
- 打开
Main.storyboard
.文档大纲窗口
默认情况下应该在故事板窗口的左侧可见.如果没有,请单击情节提要窗口左侧View As: iPhone 7
旁边的图标. - 在
storyboard
中选择对象,比较容易找到,然后从storyboard
的document outline
中选择. - 如果最右侧尚未打开,请打开
Utility window
.使用快捷键Cmd-Option-0
(command-option-zero),切换实用程序窗口的打开/关闭. - 点击
右箭头
图标(最右上角的图标)打开连接检查器.单击连接旁边的x
图标,删除任何不需要的 IBOutlet/IBAction 或您想要删除的任何其他连接. - 重新创建连接.您也可以直接从
connection window
中element
旁边的circle
拖动到特定的object
.否则,按照您现在一直在做的方式添加连接.
至于Class文件和其他编码文件.您可以只注释掉以前具有 IBAction
或 IBOutlet
的行.并手动重新输入同一行(不要剪切和粘贴
).从 storyboard
重新添加连接,你应该很好.不要忘记删除您注释掉的不再需要的行.
I renamed a class, which happened to have an outlet connection to a label called mainLabel in a storyboard file. When I run my program, it crashes and gives me the error: "this class is not key value coding-compliant for the key mainLabel".
Other SO answers have shown this to be caused by a bad outlet connection, so I removed the connection and removed any lose ends. When trying to reconnect the label to an outlet in my code, I get the error Could not insert new outlet connection: Could not find any information for the class named CourseTableViewCell
Other SO answers have provided solutions which I have tried and haven't worked including:
- Deleting the reference to the file and re-adding it
- Cleaning the project
- Deleting the derived data folder
- deleting the label and re-adding it
- Dragging from the code to storyboard rather than vice-versa
I made sure that the correct file name was listed in the identity inspector, under "Custom Class". If anybody has any other ideas, please let me know!
I can provide more information if necessary.
The following steps are what you need to do to find existing IBOutlet / IBAction from and object. Be it label
, button
, etc. And how to remove it.
- Open
Main.storyboard
. TheDocument outline window
should be visible by default on the left of your storyboard window. If not, click the icon on left of the storyboard window, next to theView As: iPhone 7
. - Select the object in
storyboard
, it's easier to find and then select it from thedocument outline
of thestoryboard
. - Open the
Utility window
if not yet open on the most right side. Use shortcut keyCmd-Option-0
(command-option-zero), to toggle open/close of the utility window. - Open the connection inspector by click on
right arrow
icon (top right most icon). Remove any unwanted IBOutlet / IBAction or any other connection you want to remove by clicking on thex
icon next to the connection. - Recreate the connection. You could also drag directly from the
circle
next to theelement
in theconnection window
for a particularobject
. Else add the connection the way you have been doing for now.
As for the Class file and other coding file. You could just comment out the lines that previously have IBAction
or IBOutlet
. And retype the same line manually (don't cut and paste
). Add back the connection from storyboard
, and you should be good. Don't forget to delete the lines you commented out that you don't need anymore.
这篇关于重命名类导致 IBOutlet 连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!