0
如果特定的值被調用,我想發佈一個特定的圖像,這是我的理解這是不工作,因爲NSNumber未正確轉換爲NSString,但我不確定是否這就是問題。通過使用NSLog,我發現數據正在通過,比如評分爲4.5,在這種情況下,我想顯示四星半,但圖片不會發布。我已經證實視圖已經連接起來,並且所有東西都連接起來了,但沒有骰子。下面的代碼。反饋非常感謝!顯示特定於NSString值的圖像
- (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];
}
Ack!一個常見的問題,如果我沒有弄錯:「isEqualToString」vs「==」.......我很愚蠢,我應該知道「isEqualToString」可能會解決這個問題!感謝您的時間:) – Greg 2013-02-25 03:57:44
@ greg23af如果您發現答案令人滿意,請使用左側的複選框標記。 (http://i.stack.imgur.com/uqJeW.png) – 2013-02-25 04:00:23
此外,你應該更新到最新版本的Xcode,它應該爲此產生一個警告。 – 2013-02-25 04:01:17