ios [__NSCFNumber length]:无法识别的选择器发送到实例 UITableView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21846792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:28:07  来源:igfitidea点击:

[__NSCFNumber length]: unrecognized selector sent to instance UITableView

iosobjective-cjsonuitableviewnsmutablearray

提问by lhencq

i'm experiencing an error

我遇到了错误

[__NSCFNumber length]: unrecognized selector sent to instance 0x15580c90 2014-02-18 15:10:49.490 CIB[1706:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x15580c90' *First throw call stack: (0x2da18e83 0x37d756c7 0x2da1c7b7 0x2da1b0af 0x2d969dc8 0x2e33b695 0x2e33b169 0x301ab2fd 0x1603ad 0x302cf315 0x302776cd 0x30276ef1 0x3019d353 0x2fe23943 0x2fe1f167 0x2fe1eff9 0x2fe1ea0d 0x2fe1e81f 0x2fe1854d 0x2d9e3f69 0x2d9e18f7 0x2d9e1c43 0x2d94c471 0x2d94c253 0x326862eb 0x30201845 0x113de1 0x3826eab7) libc++abi.dylib: terminating with uncaught exception of type NSException

[__NSCFNumber 长度]:无法识别的选择器发送到实例 0x15580c90 2014-02-18 15:10:49.490 CIB[1706:60b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFNumber lengthized] 选择器到实例0x15580c90' *第一掷调用堆栈:(0x2da18e83 0x37d756c7 0x2da1c7b7 0x2da1b0af 0x2d969dc8 0x2e33b695 0x2e33b169 0x301ab2fd 0x1603ad 0x302cf315 0x302776cd 0x30276ef1 0x3019d353 0x2fe23943 0x2fe1f167 0x2fe1eff9 0x2fe1ea0d 0x2fe1e81f 0x2fe1854d 0x2d9e3f69 0x2d9e18f7 0x2d9e1c43 0x2d94c471 0x2d94c253 0x326862eb 0x30201845 0x113de1 0x3826eab7)的libc ++ abi.dylib:与未捕获的终止NSException 类型的异常

I have loop here. from array in Json to my model tasklist then stored to NSMutableArray _tasklist

我这里有循环。从 Json 中的数组到我的模型任务列表,然后存储到 NSMutableArray _tasklist

NSArray *taskJson = [json objectForKey:@"fOTaskListModelWss"];

    for (NSDictionary *dictCQ in taskJson) {
        NSLog(@"TASKLIST: %@", [dictCQ objectForKey:@"foTaskListModelWs"]);

        NSDictionary *datadic = [dictCQ objectForKey:@"foTaskListModelWs"];
        TaskList *task = [[TaskList alloc]init];
        [task setTaskCount:datadic[@"count"]];
        [task setFuncCd:datadic[@"funcCd"]];
        [task setFuncCdDscp:datadic[@"funcCdDscp"]];
        [task setRequestStatus:datadic[@"requestStatus"]];
        [task setRole:datadic[@"role"]];
        [_taskList addObject:task];
    }

then here is my code in cellForRowAtRowPathIndex

那么这是我在 cellForRowAtRowPathIndex 中的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * simpleTableIdentifier = @"MenuTableViewCell";
MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuTableViewCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
TaskList *txn = [_taskList objectAtIndex:indexPath.row];
cell.titleLabel.text = txn.funcCdDscp;
cell.totalCountLabel.text = txn.taskCount;
return cell;}

回答by Steven Fisher

cell.titleLabel.text = txn.funcCdDscp;
cell.totalCountLabel.text = txn.taskCount;

One of these (not sure which, but my guess would be taskCount) is a NSNumber. Text takes an NSString.

其中之一(不确定是哪个,但我的猜测是taskCount)是 NSNumber。文本需要一个 NSString。

回答by codercat

cell.titleLabel.text = txn.funcCdDscp;
cell.totalCountLabel.text = [txn.taskCount stringValue];

OR

或者

Use this as this is best solution

按原样使用它 best solution

cell.totalCountLabel.text = [NSString stringWithFormat:@"%@",txn.taskCount];

回答by muthukumaresh

Hope the following will help you if you are manipulating JSON data from webservice

如果您正在处理来自 webservice 的 JSON 数据,希望以下内容对您有所帮助

cell.textLabel.text=[NSString stringWithFormat:@"%@",[[JsonDictionaryObject objectForKey:@"Respected_Key_Name"]objectAtIndex:indexPath.row]];

回答by Priyanka

Here it is expecting NSStringinstead of NSNumberso that is the reason it crashes.So convert that to NSStringthen it will be resolved.

这里是期待NSString而不是NSNumber所以这就是它崩溃的原因。所以将其转换为NSString然后它将被解决。