美文网首页ios开发iOS bug修复iOS Developer
iOS Xcode, 解决“Could not insert n

iOS Xcode, 解决“Could not insert n

作者: DengF_Zhang | 来源:发表于2016-07-19 14:01 被阅读2827次

在Xcode中,我们可以在StoryBoard编辑界面或者是xib编辑界面中通过“Control键+拖拽“的方式将某个界面元素和对应的代码文件连接起来,在代码文件中创建outlet。

不过,如果你的运气不太好,执行以上操作的过程中你可能会遇到下面这样的错误:

Could not insert new outlet connection: Could not find any information for the class named "xxx".

其中的“xxx”就是你的目标代码文件中的类名。如果自己没有错误,这完全是Xcode的原因。

下面,介绍一种简单方便的方法:

1: 删除并重新添加.h和.m文件

选中出问题的.m和.h文件,点删除键,然后选“Remove Reference”,不要真正删除文件。接着选“File -> Add Files to ...”菜单,在文件选择界面选择刚才的.m文件和.h文件将他们重新加入项目中。

马上试一下是不是已解决!

2: 最近有朋友反映不能够解决,可以这样

在Xcode中选择“Windows->Organizer”,然后选择“Projects”,选中你正在处理的项目,点击“DeriveData”对应的“Delete”按钮,Xcode会删除该项目的DeriveData,然后自动重新生成一个。重新启动Xcode。还不行请重启电脑,亲测可行。

相关文章

网友评论

  • yuebiubiu:试完了上面的各个方法,还是不行
    yuebiubiu:都试过啦,还是不行,刚在Stack Overflow 找到了一个办法可以暂时先用着,给你分享一下:
    1,Clean the project (Product > Clean)
    2,Manually paste in
    @IBOutlet weak var viewName: UIView!
    // or
    @IBAction func viewTapped(_ sender: Any) { }
    and control drag to it. (Change type as needed.) (Idea from this answer. Please upvote it.)
    3,Completely close Xcode and restart your project.
    4,Delete the Derived Data folder (Go to Xcode > Preferences > Locations and click the gray arrow by the Derived Data folder. Then delete your project folder.)
    5,Click delete on the class, remove reference (not Move to Trash), and add it back again.
    DengF_Zhang:这是Xcode的bug这两个方法都试了吗?删掉后再command + k清一下,重启xcode,重启电脑

本文标题:iOS Xcode, 解决“Could not insert n

本文链接:https://www.haomeiwen.com/subject/mzvmjttx.html