ios Xcode 4:创建 UIView xib,未正确连接

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

Xcode 4: Creating a UIView xib, not properly connecting

iosxcodexcode4

提问by Tim Sullivan

I'm trying to create a nib that contains a view that will be embedded in a TableViewCell. I've created the interface and implementation files, ResultCell.hand ResultCell.m. They're stock, out-of-the-box, no code changes.

我正在尝试创建一个包含将嵌入到 TableViewCell 中的视图的笔尖。我已经创建了接口和实现文件,ResultCell.h以及ResultCell.m. 它们是现货,开箱即用,无需更改代码。

I then create an empty XIB file, and drag a UIView onto it. Then I click File's Owner, and set the type to ResultCell. I click the view, and set its class to also be ResultCell.

然后我创建一个空的 XIB 文件,并将一个 UIView 拖到它上面。然后我单击文件的所有者,并将类型设置为ResultCell. 我单击视图,并将其类设置为ResultCell.

Here are the problems I have:

以下是我遇到的问题:

  1. When using the Assistant Editor view (which I live in), the ResultCell.hfile doesn't appear when I'm viewing the ResultCell.xib file. I have to force it to load by clicking on Automatic and selecting the file.
  2. When I drop a label in the view, and then Ctrl+Click and drag to the .h to create an outlet, I get this error message: "Could not insert new outlet connection:Could not find any information about the class named ResultCell."
  1. 使用“助理编辑器”视图(我所在的视图)时,在ResultCell.h查看 ResultCell.xib 文件时该文件不会出现。我必须通过单击“自动”并选择文件来强制加载它。
  2. 当我在视图中放置一个标签,然后按 Ctrl+单击并拖动到 .h 以创建出口时,我收到此错误消息:“无法插入新的出口连接:找不到有关名为 ResultCell 的类的任何信息。 ”

I've tried creating and re-creating the view, and it's just not working, and I've started to lose my patience. Any help would be very, very appreciated!

我尝试创建和重新创建视图,但它不起作用,我开始失去耐心。任何帮助将非常非常感谢!

采纳答案by Defragged

This might not work for your specific issue, but occasionally I get that error when working with newly created nibs. Deleting and recreating the nibs and View Controllers with the same names as before didn't resolve the issue, but relaunching Xcode did.

这可能不适用于您的特定问题,但有时我在使用新创建的笔尖时会遇到该错误。删除并重新创建与以前相同名称的笔尖和视图控制器并不能解决问题,但重新启动 Xcode 可以。

回答by David Pisoni

I got into a similar state just today. It was very odd: I could attach any XIB (new or existing) to any already-existing ViewController class in the project, but I could not create a new ViewController and have it attach properly to any XIB. The "assistant" functionality didn't work, nor did the IB-to-headerfile-connection functionality.

就在今天,我也进入了类似的状态。这很奇怪:我可以将任何 XIB(新的或现有的)附加到项目中任何已经存在的 ViewController 类,但我无法创建新的 ViewController 并将其正确附加到任何 XIB。“助手”功能不起作用,IB 到头文件的连接功能也不起作用。

Closing the project and re-opening did not fix it.
Quitting XCode and restarting did not fix it.
Creating a new project and testing the functionality worked fine, which led me to believe there was something corrupt in some cache somewhere.

关闭项目并重新打开并没有解决它。
退出 XCode 并重新启动并没有修复它。
创建一个新项目并测试功能运行良好,这让我相信某个缓存中的某些内容已损坏。

My solution

我的解决方案

  • Close your project.
  • Go to the ~/Library/Developer/XCode/DerivedData folder and REMOVE all subfolders there referencing the project you are working on.
  • Open your project in XCode. The problem should be fixed now.
  • 关闭您的项目。
  • 转到 ~/Library/Developer/XCode/DerivedData 文件夹并删除所有引用您正在处理的项目的子文件夹。
  • 在 XCode 中打开您的项目。现在应该解决这个问题。

Incidentally, just running a full clean did not seem to clear things up. I had to trash the derived data. I'm certain I got into this position because of git games I was playing, but I had no idea how to get out, because even switching back to earlier git revisions didn't help. (That was a big clue also that it was something untracked by the project itself.)

顺便说一句,仅仅运行一次完全清理似乎并没有解决问题。我不得不丢弃派生数据。我确定我进入这个职位是因为我在玩 git 游戏,但我不知道如何退出,因为即使切换回早期的 git 修订版也无济于事。(这也是一个很大的线索,它是项目本身没有跟踪的东西。)

回答by jasongregori

I just had this problem and restarting Xcode did not fix it. I removed the class files from the project then added them back in and it started working.

我刚刚遇到了这个问题,重新启动 Xcode 并没有解决它。我从项目中删除了类文件,然后重新添加它们并开始工作。

回答by Dr.Kameleon

I had the very same issue. And I tried :

我有同样的问题。我试过:

  • Restarting Xcode
  • Deleting Derived Data
  • And many more
  • 重启Xcode
  • 删除派生数据
  • 还有很多

None of that worked. What worked for me was simply to :

这些都没有奏效。对我有用的只是:

  • Remove 'suspect' class files from Project (just remove References, huh?)
  • Re-add them to the project
  • 从项目中删除“可疑”类文件(只需删除引用,是吧?)
  • 将它们重新添加到项目中

And done!

并做了!

回答by Duane Fields

If restarting Xcode doesn't work of you, I have found that Toggling the new .m file out and back into the target membership works.

如果重新启动 Xcode 对您不起作用,我发现将新的 .m 文件切换回目标成员资格是可行的。

回答by Ivan Dossev

This helped me out:

这帮助了我:

  1. from the project file Panel (left side) select the xib file that is broken.
  2. Click on the Files Owner icon from the editor view.
  3. from the properties Panel (right side) select the third tab (at the top)
  4. specify the "Custom Class"
  1. 从项目文件面板(左侧)中选择损坏的 xib 文件。
  2. 单击编辑器视图中的文件所有者图标。
  3. 从属性面板(右侧)选择第三个选项卡(在顶部)
  4. 指定“自定义类”

If you do not see a "panel", please have a look at the top-right corner of the window and enable the proper "view" buttons. If you don't see the "view" buttons then click on the top-right most capsule button.

如果您没有看到“面板”,请查看窗口的右上角并启用正确的“查看”按钮。如果您没有看到“查看”按钮,请单击最右上角的胶囊按钮。

回答by Praveen Kumar

I encountered the same problem today. Restarting XCode did not fix the problem for me. I was able to get things back to normal by using "Delete"option of "Derived Data"of the projectthat can be found under Organizer. Organizer says that, "Derived Data includes index, build output and logs". I guess that either indexor build outputwas causing this issue.

我今天遇到了同样的问题。重新启动 XCode 并没有解决我的问题。通过使用可以在Organizer下找到的项目“派生数据”“删除”选项,我能够使事情恢复正常。组织者说,“派生数据包括索引、构建输出和日志”。我猜是索引构建输出导致了这个问题。

回答by Peter Lapisu

in XCode go to organizer, click project, click delete derived data... than clean the project

在 XCode 中转到管理器,单击项目,单击删除派生数据...比清理项目

回答by A.S.

I noticed that .m file was moved inside en.lproj folder.

我注意到 .m 文件被移动到 en.lproj 文件夹中。

Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.It will fix the issue.

只需从 Xcode 中删除(仅供参考).m 文件并将 .m 移出 en.lproj。再次添加它会解决问题。

Don't worry, you will get all your connections back.

别担心,您将恢复所有连接。

回答by jakob.j

In my case it helped to make a "fake change" (just a space) to the according header file.

在我的情况下,它有助于对相应的头文件进行“假更改”(只是一个空格)。