重命名类导致 IBOutlet 连接失败 [英] Renaming class causes IBOutlet connection to fail

查看:33
本文介绍了重命名类导致 IBOutlet 连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重命名了一个类,该类碰巧与故事板文件中名为 mainLabel 的标签有一个插座连接.当我运行我的程序时,它崩溃并给我一个错误:这个类不是键 mainLabel 的键值编码兼容".

其他 SO 答案表明这是由插座连接不良引起的,因此我删除了连接并删除了任何丢失的一端.在我的代码中尝试将标签重新连接到插座时,出现错误 无法插入新的插座连接: 找不到名为 CourseTableViewCell 的类的任何信息

其他 SO 答案提供了我尝试过但没有奏效的解决方案,包括:

  • 删除对文件的引用并重新添加
  • 清理项目
  • 删除派生数据文件夹
  • 删除标签并重新添加
  • 从代码拖到故事板,而不是相反

我确保在身份检查器中的自定义类"下列出了正确的文件名.如果有人有任何其他想法,请告诉我!

如有必要,我可以提供更多信息.

解决方案

以下步骤是您从和对象中查找现有 IBOutlet/IBAction 所需要做的.是labelbutton 等等.以及如何删除它.

  1. 打开Main.storyboard.文档大纲窗口 默认情况下应该在故事板窗口的左侧可见.如果没有,请单击情节提要窗口左侧 View As: iPhone 7 旁边的图标.
  2. storyboard中选择对象,比较容易找到,然后从storyboarddocument outline中选择.
  3. 如果最右侧尚未打开,请打开 Utility window.使用快捷键Cmd-Option-0 (command-option-zero),切换实用程序窗口的打开/关闭.
  4. 点击右箭头图标(最右上角的图标)打开连接检查器.单击连接旁边的 x 图标,删除任何不需要的 IBOutlet/IBAction 或您想要删除的任何其他连接.
  5. 重新创建连接.您也可以直接从 connection windowelement 旁边的 circle 拖动到特定的 object.否则,按照您现在一直在做的方式添加连接.

至于Class文件和其他编码文件.您可以只注释掉以前具有 IBActionIBOutlet 的行.并手动重新输入同一行(不要剪切和粘贴).从 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.

  1. Open Main.storyboard. The Document 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 the View As: iPhone 7.
  2. Select the object in storyboard, it's easier to find and then select it from the document outline of the storyboard.
  3. Open the Utility window if not yet open on the most right side. Use shortcut key Cmd-Option-0 (command-option-zero), to toggle open/close of the utility window.
  4. 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 the x icon next to the connection.
  5. Recreate the connection. You could also drag directly from the circle next to the element in the connection window for a particular object. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆