1
下面的代码返回天气数据。除了当前的天气描述,所有工作都很好。例如,如果todaysimage文件名是partlycloudyv3.png
。该描述在我的应用中显示为partlycloudy
。我怎样才能让它看起来像partly cloudy
?解析标签Xcode的文件名
- (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;
}