如果调用了特定值,我正在尝试发布特定图像,我的理解是这不起作用,因为 NSNumber 没有正确转换为 NSString,但我不确定这是否是问题。通过使用NSLog,我看到数据是通过的,比如一个评分是4.5,这样的话我想显示四星半,但是图片不贴。我已经验证了视图已链接,并且所有内容都已连接,但没有骰子。代码如下。反馈非常感谢!
- (void) connectionDidFinishLoading:(NSURLConnection *)connection
{
[self setString];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSString *string1 = [dic objectForKey:@"name"];
NSString *string2 = [[dic objectForKey:@"rating"]stringValue];
NSLog(@"RATE STRING ---> %@", string2);
if (string2 == @"0")
{
UIImage *img = [UIImage imageNamed:@"zerorate.png"];
[imageView2 setImage:img];
}
if (string2 == @"1")
{
UIImage *img = [UIImage imageNamed:@"onerate.png"];
[imageView2 setImage:img];
}
if (string2 == @"1.5")
{
UIImage *img = [UIImage imageNamed:@"onehalfrate.png"];
[imageView2 setImage:img];
}
if (string2 == @"2")
{
UIImage *img = [UIImage imageNamed:@"tworate.png"];
[imageView2 setImage:img];
}
if (string2 == @"2.5")
{
UIImage *img = [UIImage imageNamed:@"twohalfrate.png"];
[imageView2 setImage:img];
}
if (string2 == @"3")
{
UIImage *img = [UIImage imageNamed:@"threerate.png"];
[imageView2 setImage:img];
}
if (string2 == @"3.5")
{
UIImage *img = [UIImage imageNamed:@"threehalfrate.png"];
[imageView2 setImage:img];
}
if (string2 == @"4")
{
UIImage *img = [UIImage imageNamed:@"fourrate.png"];
[imageView2 setImage:img];
}
if (string2 == @"4.5")
{
UIImage *img = [UIImage imageNamed:@"fourhalfrate.png"];
[imageView2 setImage:img];
}
if (string2 == @"5")
{
UIImage *img = [UIImage imageNamed:@"fiverate.png"];
[imageView2 setImage:img];
}
[[self myTableView] reloadData];
}