A new user cell from XIB that causes encoding of a key value for a key ...?

I have a custom table view cell that I created using XIB:

enter image description here

I also linked the XIB file to my custom UITableView cell.

But now when I try to load a cell into - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath with the following codes:

 MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { // Load the top-level objects from the custom cell XIB. NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:cell options:nil]; // Grab a pointer to the first object (presumably the custom cell, as that all the XIB should contain). cell = [topLevelObjects objectAtIndex:1]; } 

I will get [<NSObject 0x8a5b970> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key hitMeButton.

I searched on the Internet, and one of the possible reasons may be that the XIB is not connected with IBOutlet, I checked so that it seems that it is not.

+6
source share
2 answers

I just solved the problem, but I'm not sure if this is the most suitable way.

 if (cell == nil) { MyCustomTableViewCell *aCell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:aCell options:nil]; cell = [topLevelObjects objectAtIndex:0]; } 
-2
source

The real problem is how you linked the outputs. You should associate your output with TableViewCell with labels in your cell (you probably linked the label to the file owner)

Here are some more explicative images:

This is normal enter image description here



This is not true enter image description here

+30
source

Source: https://habr.com/ru/post/901581/


All Articles