繁体   English   中英

目标C错误[__NSCFNumber长度]:无法识别的选择器已发送到实例

[英]Objective C error [__NSCFNumber length]: unrecognized selector sent to instance

我正在写一个基于tableView的应用程序。 当我在tableView中使用默认单元格时,一切都很完美。 当我尝试制作海关单元格时出现以下错误:

2014-12-01 22:50:01.690 Signaturegourmande[15701:624637] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb0000000000000c3
2014-12-01 22:50:01.716 Signaturegourmande[15701:624637] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb0000000000000c3'

当我有这个代码时应用程序工作:

static NSString *simpleTableIdentifier = @"SimpleTableItem";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [nomData objectAtIndex:indexPath.row];
    return cell;

当我用以下代码替换代码时出现错误:

static NSString *simpleTableIdentifier = @"ProduitCell";
    ProduitCell *cell = (ProduitCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProduitCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.nameLabel.text = [nomData objectAtIndex:indexPath.row];
    cell.thumbnailImageView.image = [UIImage imageNamed:[urlData objectAtIndex:indexPath.row]];
    cell.priceLabel.text = [prixData objectAtIndex:indexPath.row];

    return cell;

我用“.h”和“.m”创建了一个“ProduitCell”类,我的.h文件中有3个属性。 我已将StoryBoard中的这些属性与我的Xib中的右侧单元格项链接起来。

谢谢你的帮助。

检查下面的行,如果它是NSNumber类类型,则使用stringValue在下面更改: -

cell.priceLabel.text = [[prixData objectAtIndex:indexPath.row]stringValue];

我做到了:

cell.priceLabel.text = [NSString stringWithFormat:@"%@",[prixData objectAtIndex:indexPath.row]];

谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM