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

lhe*_*ncq 32 json objective-c uitableview nsmutablearray ios

我遇到了错误

[__NSCFNumber length]:无法识别的选择器发送到实例0x15580c90 2014-02-18 15:10:49.490 CIB [1706:60b] *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFNumber length]:无法识别的选择器已发送到实例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类型的异常

我在这里循环.从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];
    }
Run Code Online (Sandbox Code Playgroud)

那么这是我在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;}
Run Code Online (Sandbox Code Playgroud)

Ste*_*her 87

cell.titleLabel.text = txn.funcCdDscp;
cell.totalCountLabel.text = txn.taskCount;
Run Code Online (Sandbox Code Playgroud)

其中一个(不确定哪个,但我猜的是taskCount)是一个NSNumber.Text采用NSString.


cod*_*cat 19

cell.titleLabel.text = txn.funcCdDscp;
cell.totalCountLabel.text = [txn.taskCount stringValue];
Run Code Online (Sandbox Code Playgroud)

要么

这样使用它 best solution

cell.totalCountLabel.text = [NSString stringWithFormat:@"%@",txn.taskCount];
Run Code Online (Sandbox Code Playgroud)

  • stringValue有帮助.+1 (2认同)

小智 5

如果您正在从webservice操作JSON数据,希望以下内容对您有所帮助

cell.textLabel.text=[NSString stringWithFormat:@"%@",[[JsonDictionaryObject objectForKey:@"Respected_Key_Name"]objectAtIndex:indexPath.row]];
Run Code Online (Sandbox Code Playgroud)