Good day. There is a project in Objective c. There is a controller with the tableView element and there is a tableViewCell class (in which there are two labels), from which I take a cell for the tableView. And all this works fine until I announce links for any label. The application crashes with the following error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[setValue: forUndefinedKey:]:

I announce the connection through file's owner.

Link declaration code in tableViewCell header:

@interface CafeCell:UITableViewCell @property (weak, nonatomic) IBOutlet UILabel *lbl_CafeName; @end 

Table build code:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CafeCell"; CafeCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell==nil){ cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];//падает здесь } return cell; } 
  • Throw off the code, it will be easier to catch it. There are several things that can lead to this result. For example, the IB class is given the wrong name, or if you made a connection and then renamed something and so on. - Max Mikheyenko

2 answers 2

All you need to do in the cellForRowAtIndexPath class:

 static NSString *CellIdentifier = @"CafeCell"; CafeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.lbl_CafeName.text = @"Your text"; 

And do not forget to register the cell if it is built in a separate Xib:

 UINib *cellNib = [UINib nibWithNibName:@"CafeCell" bundle:nil]; [self.tableView registerNib:cellNib forCellReuseIdentifier:@"CafeCell"]; 

    Try changing this piece of code:

     cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0]; 

    On:

     cell = [[CafeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    And now you can set the desired value for your UILabel:

     cell.lbl_CafeName.text = yourValue;