【发布时间】:2015-03-19 20:39:51
【问题描述】:
我在表格中显示了一组来自 Web 服务的字典。这是 cellForRowAtIndexPath 中的代码 sn-p。
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";
【问题讨论】:
-
“4.3”似乎是
NSNumber而不是NSString。 -
我认为这是因为您试图将 NSNumber 设置为文本属性。 text 属性需要一个 NSString。你可以试试:
cell.reviewScoreLabel.text = [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"rating"]];请看下面我的回答。 -
非常感谢门诺。它的工作原理!
标签: ios objective-c