gabaum10
gabaum10

Reputation: 3827

Custom UITableViewCell erroring

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

Upvotes: 5

Views: 1326

Answers (3)

gabaum10
gabaum10

Reputation: 3827

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!

Upvotes: 1

Stelian Iancu
Stelian Iancu

Reputation: 2492

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.

Upvotes: 5

Saa
Saa

Reputation: 1615

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]; 

Upvotes: 1

Related Questions