好的,这很奇怪,但基本上,我的应用程序通过json收集天气数据,解析它并将温度和当前条件转换为NSStrings,出于某种原因,我有2个问题,它从不在模拟器中工作,它仅适用于iOS设备,最近我无法将其显示为“Scattered Clouds”作为图像,所有图像都存储在没有文件扩展名的资源文件夹中(Scattered Clouds而不是Scattered Clouds.png等)所以我一直想知道我的代码是否只是废话?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:jsonresponse options:NSJSONReadingMutableLeaves error:&myError];
NSArray *results = [res objectForKey:@"current_observation"];
NSArray *cur = [results valueForKey:@"weather"];
NSArray *tmp = [results valueForKey:@"temp_f"];
NSLog(@"Current conditions: %@, %@º", cur, tmp);
NSString *tmpstring = [tmp description];
NSString *weatherimagestring = [cur description];
UIImage *weatherimage = [UIImage imageNamed:[NSString stringWithFormat:weatherimagestring]];
[weather setImage:weatherimage];
temp.text = [NSString stringWithFormat:@"%@%@",
tmpstring,@"°"];
}
有什么想法?基本上我只是想知道是否有更好的方法可以帮助解决这些神秘的问题..谢谢..