以下代码返回天气数据。除了当前的天气描述外,一切正常。例如,如果todaysimage文件名是partlycloudyv3.png
。我的应用中的说明显示为partlycloudy
。如何将其显示为partly cloudy
?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSArray *theView = [[NSBundle mainBundle] loadNibNamed:@"HipSkin01" owner:self options:nil];
UIView *nv = [theView objectAtIndex:0];
NSString *filePathDocArray = [DOCUMENTS stringByAppendingPathComponent:@"r.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePathDocArray]) {
NSLog(@"The file exists");
dataz = [[NSMutableDictionary alloc] initWithContentsOfFile:filePathDocArray];
NSLog(@"The file exists %@",dataz);
NSLog(@"The array: %i",(int) [dataz count]);
}
NSString *todaysimage = [dataz valueForKey:@"icon"];
[self.weatherIcon setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@v3.png", todaysimage]]];
NSArray *arr1 = [dataz objectForKey:@"display_location"];
NSString *plasez = [arr1 valueForKey:@"full"];
//NSString *plasez = [arr1 valueForKey:@"city"];
[self.plase setText:plasez];
//DataFormater
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM dd, YYYY"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *dateToday = [formatter stringFromDate:[NSDate date]];
[self.dataLable setText:dateToday];
[self.nameWeather setText:todaysimage];
//temp
NSString *tempzC = [dataz valueForKey:@"feelslike_c"];
NSString *tempzF = [dataz valueForKey:@"feelslike_f"];
NSString *terC = [NSString stringWithFormat:@"%@°C",tempzC];
NSString *terF = [NSString stringWithFormat:@"%@°F",tempzF];
[self.temprC setText:terC];
[self.temprF setText:terF];
[self addSubview:nv];
}
return self;
}
答案 0 :(得分:0)
我添加了这些行,并解析了解析问题。我在天气API中引用了不正确的项目。
NSString *todaysimage2 = [dataz valueForKey:@"weather"];
[self.weatherIcons setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@v3.png", todaysimage]]];
[self.weatherData setText:dateToday];
[self.weatherText setText:todaysimage2];