views:

49

answers:

3

Hello stackoverflow,

I am trying to build a custom table view using a cell that I built in IB. I am getting a strange error:

<BroadcastViewController 0x4b4f5f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key postText.

Everything is wired up correctly in IB to the cell controller. Not really sure why this is happening.

This is what my cellForRowAtIndexPath looks like:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//Get the folder object of interest
Broadcast *messageAtIndex = [self.messages objectAtIndex:indexPath.row] ;

static NSString *CellIdentifier = @"BroadcastTableViewCell";
static NSString *CellNib = @"BroadcastTableViewCell";

BroadcastTableViewCell *cell = (BroadcastTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
   //ERRORING ON THIS LINE...
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
    cell = (BroadcastTableViewCell *)[nib objectAtIndex:0];
}


cell.postText.text = messageAtIndex.replyText;
cell.authorName.text = messageAtIndex.postCreatorFirstName;
cell.postDate.text = messageAtIndex.creationDate;

return cell;

}

Anyone seen this kind of error before? Let me know if you need any more information...

+1  A: 

Might has something to do with dequeueReusableCellWithIdentifier returning an UITableViewCell*.

I normaly do this:

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier...
CustomCell* acell = (CustomCell*)cell; 

Set the owner to nil.

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:nil options:nil]; 
Sander Backus
Ok I see how casting that would be a good idea, but that still doesn't help on the initial load, when the first cell is nil. Need something to handle: "if (cell == nil)"
Geoff Baum
After looking at that, that is pretty much exactly what I do now, just a longer way of putting it...
Geoff Baum
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:nil options:nil]; Set the owner to nil.
Sander Backus
That was my first thought too, but alas, it didn't work :(
Geoff Baum
Are you sure the objectAtIndex:0 is indeed your BroadcastTableViewCell?
Sander Backus
It's not even getting to that line. The problem is in the line you described above...
Geoff Baum
+3  A: 

What is really strange is that it complains that the class BroadcastViewController is not KVC compliant to postText.

As far as I can see, postText is a label in your cell, so the IBOutlet for this should be in the BroadcastTableViewCell class. So check out where you've linked the postText label in IB. Also, it can be that you had an IBOutlet in your view controller for this label, you've removed it but you forgot to delete the link in IB. Anyway, there somewhere is your problem. The fact that you have the error on that line is just because it's there you load your NIB, it doesn't have anything to do with the cell itself or with the owner.

Stelian Iancu
Alright, well I have checked and double checked the IB connections. Everything is connected properly in the BroadcastTableViewCell class. There are no lingering connections to any other view controller. It really makes no sense whatsoever...
Geoff Baum
You got it. It was something in the nib. Thanks :)
Geoff Baum
A: 

Ok figured it out. The connections in IB were indeed incorrect. I had them linked to the file's owner as opposed to the actual objects. I am going to give this too Stelian because he directed me to check out the nib. Thanks for all your help!

Geoff Baum