This question already has answers here:
How can I debug 'unrecognized selector sent to instance' error
(9个答案)
5年前关闭。
我正在表格中显示来自Web服务的词典数组。这是cellForRowAtIndexPath中的代码段。
该应用程序在以下行崩溃:
带有以下异常详细信息:
字典对象数据看起来像这样:
(9个答案)
5年前关闭。
我正在表格中显示来自Web服务的词典数组。这是cellForRowAtIndexPath中的代码段。
cell.businessNameLabel.text = [dataDict objectForKey:@"business_name"];
[cell.businessNameLabel setTextColor:[UIColor colorWithRed:1.0/255.0 green:135.0/255.0 blue:68.0/255.0 alpha:1]];
UIFont *customfont = [UIFont fontWithName:@"MyriadPro-Bold" size:16];
[cell.businessNameLabel setFont:customfont];
cell.serviceTypeLabel.text = [dataDict objectForKey:@"address"];
[cell.serviceTypeLabel setTextColor:[UIColor blackColor]];
customfont = [UIFont fontWithName:@"MyriadPro-Regular" size:11];
[cell.serviceTypeLabel setFont:customfont];
cell.businessID = [dataDict objectForKey:@"business_id"];
cell.reviewScoreLabel.text = [dataDict objectForKey:@"rating"];
return cell;
该应用程序在以下行崩溃:
cell.reviewScoreLabel.text = [dataDict objectForKey:@"rating"];
带有以下异常详细信息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000003'
字典对象数据看起来像这样:
address = "Boston, MA, United States";
"business_id" = 15;
"business_image" = "http://demo.web.com/home-business/upload/user/1420452418_.jpeg";
"business_name" = autodealersma;
lat = "42.3584865";
lng = "-71.06009699999998";
rating = "4.3";
service = "auto dealers";
最佳答案
我认为这是因为您正在尝试将NSNumber设置为文本属性。 text属性需要一个NSString。您可以尝试:cell.reviewScoreLabel.text = [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"rating"]];
关于ios - 无法在标签中显示字典对象的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28065330/
10-11 14:49