Search code examples
iphoneiosobjective-cxcodecell

Can't change label for prototype cell in iOS


I have a prototype cell with label

@property (nonatomic, strong) IBOutlet UILabel *itemName; 

declared in class ECOMAdmPanelViewCell and the class is set for the cell in Identity inspector. The outlet itemName - Label is created.

In this function

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"admPanelCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil)
        cell = [[ECOMAdmPanelViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.itemName.text = [items objectAtIndex:indexPath.row];

    // Configure the cell...

    return cell;
}

I get an error message property 'itemName' not found on object of type 'UITableViewCell'. Can anyone tell me what's wrong?


Solution

  • Change your this line

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    

    with this

     ECOMAdmPanelViewCell *cell = (ECOMAdmPanelViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];