Xcode 4.2 编译失败,原型单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7042279/
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
Xcode 4.2 Compilation Failed with prototype cell
提问by Objective Coder
I'm trying out the new Xcode 4.2 Beta and I'm wondering if my code is wrong or if I'm bumping in to an bug.
我正在试用新的 Xcode 4.2 Beta,我想知道我的代码是错误的还是我遇到了错误。
The new Storyboard feature is promising but extremely buggy at the moment. Right now I've created an simple project with a tableview. This tableview will be "Grouped style" containing UITextFields. The new "Prototype Cell" feature of storyboard let's you create a prototype cell in GUI that you can draw with the "Reuse identifier" in the method cellForRowAtIndexPath. When I drag in a UITextField in this "prototype cell" and draw it out, it works great!
新的 Storyboard 功能很有前途,但目前非常有问题。现在我已经创建了一个带有 tableview 的简单项目。此 tableview 将是包含 UITextFields 的“分组样式”。故事板的新“原型单元格”功能让您可以在 GUI 中创建原型单元格,您可以使用 cellForRowAtIndexPath 方法中的“重用标识符”绘制该单元格。当我在这个“原型单元格”中拖入 UITextField 并将其绘制出来时,效果很好!
However! When I reference this textfield to an outlet in my code I get the error: Uncategorized Compilation failed. Unable to write to path:...(Path to DerivedData)
然而!当我在代码中将此文本字段引用到插座时,出现错误:未分类编译失败。无法写入路径:...(DerivedData 的路径)
Why is this? Is it a bug? Anyone else get this?
为什么是这样?这是一个错误吗?其他人得到这个吗?
回答by Tony Lenzi
I've run into this problem on a couple of occasions in Xcode 4.2 (final release as well).
我在 Xcode 4.2(最终版本)中遇到过几次这个问题。
It's usually related to an outlet or other connection that you've set up that the compiler is upset about (for lack of a better term). The trick is determining which connection(s) that is.
它通常与您设置的出口或其他连接有关,编译器对此感到不安(因为缺少更好的术语)。诀窍是确定是哪个连接。
You can view the detailed output of the build process in Xcode 4.2 by doing the following:
您可以通过执行以下操作在 Xcode 4.2 中查看构建过程的详细输出:
- Switch to the log navigator in the leftmost pane
- Select "Build "
- You should see the error(s), including your compilation failed error.
- You can expand the build log for that error by clicking the right most icon (looks like a list). That should expand and display the error causing the problems.
- 切换到最左侧窗格中的日志导航器
- 选择“构建”
- 您应该会看到错误,包括编译失败错误。
- 您可以通过单击最右侧的图标(看起来像一个列表)来展开该错误的构建日志。那应该展开并显示导致问题的错误。
回答by f.perdition
If anyones still having a problem with this i found the solution is to use tags instead of outlets.
如果有人仍然对此有问题,我发现解决方案是使用标签而不是插座。
CellForRowAtIndexPath
UILabel *titleLabel = (UILabel *)[cell viewWithTag:1001];
titleLabel.text = @"Name";
CellForRowAtIndexPath
UILabel *titleLabel = (UILabel *)[cell viewWithTag:1001];
titleLabel.text = @"Name";
回答by Nutela
OK a collegue of mine showed me the connections inspector and voila, there was an old connection causing the build failure. So select the .storyboard file, open the connections inspector (the last with the arrow) and it will give you an overview of all the connetions.
好吧,我的一位同事向我展示了连接检查器,瞧,有一个旧连接导致构建失败。所以选择 .storyboard 文件,打开连接检查器(最后一个带箭头的),它会给你所有连接的概述。
回答by Jarson
I got this error when I tried to put a / in the name of a storyboard ID. Check that you are using safe characters! (Doh!)
当我尝试在故事板 ID 的名称中添加 / 时出现此错误。检查您使用的是安全字符!(呸!)
回答by TroX
I don't have the perfect solution to your problem but I had the same and I found a way to make it works (without linking the outlet to the TableViewController).
我没有解决您的问题的完美解决方案,但我有同样的解决方案,并且我找到了一种使其工作的方法(无需将插座链接到 TableViewController)。
Just try to recreate your view from scratch and Build & Run every time you add a component.
每次添加组件时,只需尝试从头开始重新创建视图并构建并运行。
In order add a TableViewController => Test if it shows an empty table.
为了添加一个 TableViewController => 测试它是否显示一个空表。
Design your custom cell and link your cell's Outlets to it. (Without forgeting to change the Class of your TableViewCell) => Again test it
设计您的自定义单元并将您的单元的插座链接到它。(不要忘记更改 TableViewCell 的类)=> 再次测试
Then change the Class of the TableViewController to your class and now you would be able to access to your cell's outlets.
然后将 TableViewController 的 Class 更改为您的类,现在您将能够访问您的单元格的插座。
It worked for me. I hope it will for you.
它对我有用。我希望它对你有用。
回答by Symmetric
I had to remove the folder for my project in ~/Library/Developer/Xcode/DerivedData/ and rebuild. You can find the name of that folder in the logs using Tony's procedure above.
我不得不在 ~/Library/Developer/Xcode/DerivedData/ 中删除我的项目的文件夹并重建。您可以使用上述 Tony 的过程在日志中找到该文件夹的名称。
EDIT: I now think this is a bug in Xcode (Version 4.2.1). It's intermittent for me. To fix it I have to rebuild, sometimes two or three times. Build/Clean doesn't seem to help.
编辑:我现在认为这是 Xcode(版本 4.2.1)中的一个错误。对我来说是间歇性的。为了修复它,我必须重建,有时两到三次。构建/清理似乎没有帮助。
EDIT 2: Ok, hopefully the real problem. I had two references to my storyboard in the project navigator (probably a remnant of copying/rebuilding the project). I just removed one of them (making sure to only delete the reference!). Seems likely to be the problem (Xcode compiling the same file twice simultaneously).
编辑 2:好的,希望是真正的问题。我在项目导航器中有两个对我的故事板的引用(可能是复制/重建项目的残余)。我刚刚删除了其中一个(确保只删除引用!)。似乎可能是问题所在(Xcode 同时编译同一个文件两次)。
回答by iosMentalist
You should not add the title or the image or detail label to an outlet.
您不应将标题或图像或详细信息标签添加到出口。
Why do you need an outlet anyways ?
为什么你需要一个插座呢?
They get modified implicitly inside the code when you implement the protocols.
当您实现协议时,它们在代码中被隐式修改。

