简体   繁体   中英

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. 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.

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.

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 *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. There is no need to use the tag to find the label and assign it a value later.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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