Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[__NSCFNumber length]: unrecognized selector sent to instance UITableView

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

I have loop here. from array in Json to my model tasklist then stored to 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

- (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;}
like image 988
lhencq Avatar asked Feb 18 '14 07:02

lhencq


4 Answers

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.

like image 146
Steven Fisher Avatar answered Nov 10 '22 02:11

Steven Fisher


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

OR

Use this as this is best solution

cell.totalCountLabel.text = [NSString stringWithFormat:@"%@",txn.taskCount];
like image 42
codercat Avatar answered Nov 10 '22 03:11

codercat


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

cell.textLabel.text=[NSString stringWithFormat:@"%@",[[JsonDictionaryObject objectForKey:@"Respected_Key_Name"]objectAtIndex:indexPath.row]];
like image 5
muthukumaresh Avatar answered Nov 10 '22 03:11

muthukumaresh


Here it is expecting NSString instead of NSNumber so that is the reason it crashes.So convert that to NSString then it will be resolved.

like image 4
Priyanka Avatar answered Nov 10 '22 01:11

Priyanka