-[__NSCFNumber length]: unrecognized selector sent to instance

4.1k Views Asked by At
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell"];

    if (cell == nil)
    {
        [tableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"myCell"];
        cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell"];
    }

    if (cell.tag == 0)
    {

    }

    str = [jsonData objectAtIndex:cell.tag];

    NSDictionary *dict = [jsonData objectAtIndex:indexPath.row];
    cell.lblDeliveryTime.text = [dict valueForKey:@"sysord_ExpectedDeliveryTime"];
    cell.lblOrderPlacedTime.text = [dict valueForKey:@"sysord_OrderDateTime"];
    cell.lblDeliveryPickUP.text = [dict valueForKey:@"sysord_DeliveryType"];

    NSDictionary *dict1 = [jsonData objectAtIndex:cell.tag];

    orderidString = [dict1 valueForKey:@"sysord_ID"];

    DetailViewController *detailVC=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];


    return cell;
}
2

There are 2 best solutions below

0
On

When you assign an object from dictionary to a text, you need to make sure it's a NSString type.

cell.lblDeliveryTime.text = [[dict objectForKey:@"sysord_ExpectedDeliveryTime"] stringValue];
cell.lblOrderPlacedTime.text = [[dict objectForKey:@"sysord_OrderDateTime"] stringValue];
cell.lblDeliveryPickUP.text = [[dict objectForKey:@"sysord_DeliveryType"] stringValue];
1
On

One of the values is not a NSString but NSNumber.

I would advise you to first check the type but if you want to always convert to string, you can use:

cell.lblDeliveryPickUP.text = [NSString stringWithFormat:@"%@", dict[@"sysord_DeliveryType"]];