找到你要的答案

Q:-[__NSCFNumber length]: unrecognized selector sent to instance

Q:- [长度]:不__nscfnumber选择器送到实例

- (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;
}
- (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;
}
answer1: 回答1:

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

当你将从字典对象的文本,你需要确保它是一个NSString类型。

cell.lblDeliveryTime.text = [[dict objectForKey:@"sysord_ExpectedDeliveryTime"] stringValue];
cell.lblOrderPlacedTime.text = [[dict objectForKey:@"sysord_OrderDateTime"] stringValue];
cell.lblDeliveryPickUP.text = [[dict objectForKey:@"sysord_DeliveryType"] stringValue];
answer2: 回答2:

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

一个人的价值不是一个NSString但NSNumber。

我建议你先检查类型,但如果你想始终转换为字符串,您可以使用:

cell.lblDeliveryPickUP.text = [NSString stringWithFormat:@"%@", dict[@"sysord_DeliveryType"]];
objective-c  uitableview  xib