简体   繁体   English

无法编译连接iOS5

[英]Can't compile connection iOS5

On an app I'm working on for the iPhone, it has decided to not compile on me when I ask it to give me an outlet to a label on a prototype table cell. 在我正在为iPhone开发的一个应用程序上,当我要求给我一个原型表单元格上的标签的出口时,它决定不对我进行编译。 I've gotten outlets for labels before, but I was using either just a standard view or static cells rather than prototype cells. 以前我已经有了标签的销售点,但是我只是在使用标准视图或静态单元格,而不是原型单元格。 I'm thinking it probably has to do with the fact that the label belongs to a prototype cell and will be duplicated since they all have the same identifier (Cell), but then again I could be off. 我想这可能与标签属于原型单元并且将被复制的事实有关,因为它们都具有相同的标识符(单元),但是我又可能会退出。 I'm not sure what to do with this one, if I use just cell.textLabel.text then my upload button doesn't show up until after I click on the cell. 我不确定该怎么做,如果我只使用cell.textLabel.text那么直到单击单元格后,我的上载按钮才会显示。

The Error: 错误:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x4007cd200  <IBProxyObject: 0x4007de280> => lblServerName2 => <IBUILabel: 0x4009b7d00>>

Does anyone have any suggestions as to how I could go about setting the text on a custom label inside a cell? 是否有人对我如何在单元格内的自定义标签上设置文本有任何建议?

For reference, I've uploaded my project here . 供参考,我在这里上传了我的项目。 It's a mess at the moment, but it's currently just a proof on concept kind of thing. 目前这是一团糟,但目前仅是概念方面的证明。 I'm going to go through and do clean up once I get it working. 一旦工作,我将进行清理。

Any suggestions are appreciated. 任何建议表示赞赏。

EDIT: 编辑:

This page helped out. 页面帮助了您。 I found it almost immediately after posting this question. 发布此问题后,我几乎立即找到了它。 Basically, I set the tag of my label to 100 and then used this code inside of the cellForRowAtIndexPath method. 基本上,我将标签的标签设置为100,然后在cellForRowAtIndexPath方法中使用此代码。

UILabel *lblServerName = (UILabel*)[cell viewWithTag:100];
lblServerName.text=[server getName];

and there it was, my label working correctly and my button showing up. 在那里,我的标签正常工作,并且显示了我的按钮。

To change the text in a label on an arbitrary UITableViewCell, assign a tag to the label, and then in code do something like the following: 要更改任意UITableViewCell上标签中的文本,请为标签分配一个标签,然后在代码中执行以下操作:

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:2]];
if (cell != nil) {
    // This assumes that you set the tag to 1 on the label
    UILabel *label = (UILabel *)[cell viewWithTag:1];
    label.text = @"New Text";
}

This question provides a more likely explanation for this error message. 该问题为该错误消息提供了更可能的解释。

As illustrated in WWDC 2011 Session 309, prototype cells can absolutely have outlets that are connected up to the cell's custom subclass. 如WWDC 2011 Session 309中所示,原型单元绝对可以具有连接到单元的自定义子类的插座。 There is no need to use the tag to find the label and assign it a value later. 无需使用tag来查找标签,以后再为其分配值。

What probably happened in your project (I didn't look at it) is that you had a reference from your prototype cell to another object in your storyboard. 您的项目中可能发生的事情(我没有看过)是您有一个原型单元到情节提要中另一个对象的引用。 This is not valid because a prototype cell isn't a real cell. 这是无效的,因为原型单元不是真正的单元。 There could be zero or a thousand of them. 可能是零或一千。 Remove the outward-pointing connection and the error will disappear. 删除指向外的连接,错误将消失。

(In my case, I had connected up a segue from a prototype cell to another view controller, thinking that a tap on it would segue to that view controller.) (在我的情况下,我已经将一个样例从原型单元连接到另一个视图控制器,以为轻按它可以将那个样例连接到该视图控制器。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM