我正在尝试在UILabels上显示天气数据值(通过进行API调用获取),这是代码:
self.maxTempField.text = [NSString stringWithFormat:@"%@",vari[@"main"][@"\"temp_max\""]];
NSLog(@"Max Temp %@", vari[@"main"][@"temp_max"]);
self.atmosphericPresField.text = [NSString stringWithFormat:@"%@", vari[@"main"][@"pressure"]];
self.windSpeed.text = [NSString stringWithFormat:@"%@", vari[@"wind"][@"speed"]];
NSLog(@"Speeed of the wind %@", vari[@"wind"][@"speed"]);
我无法理解为什么标签没有更新。我还尝试将UILabel
替换为UITextField
,但问题仍然存在。以下是按钮操作的完整代码:
- (IBAction)moreProperties:(id)sender {
UIStoryboard *refToStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *pointerToMoreValuesVC = [refToStoryBoard instantiateViewControllerWithIdentifier:@"MorePropertiesVC"];
pointerToMoreValuesVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:pointerToMoreValuesVC animated:YES completion:nil];
self.noteLabel.text = @"Random Text";
dispatch_async(dispatch_get_main_queue(), ^{
self.maxTempField.text = [NSString stringWithFormat:@"%@",vari[@"main"][@"\"temp_max\""]];
NSLog(@"Max Temp %@", vari[@"main"][@"temp_max"]);
self.atmosphericPresField.text = [NSString stringWithFormat:@"%@", vari[@"main"][@"pressure"]];
self.windSpeed.text = [NSString stringWithFormat:@"%@", vari[@"wind"][@"speed"]];
NSLog(@"Speeed of the wind %@", vari[@"wind"][@"speed"]);
});
}
我还检查了所有标签连接,它们很好。
答案 0 :(得分:0)
现在使用ViewController.h中的类对象访问所有插座
- (IBAction)moreProperties:(id)sender {
UIStoryboard *refToStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
WetherDetail *pointerToMoreValuesVC = [refToStoryBoard instantiateViewControllerWithIdentifier:@"MorePropertiesVC"];
pointerToMoreValuesVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:pointerToMoreValuesVC animated:YES completion:nil];
pointerToMoreValuesVC.noteLabel.text = @"Random Text";
pointerToMoreValuesVC.maxTempField.text = [NSString stringWithFormat:@"%@",vari[@"main"][@"temp_max"]];
pointerToMoreValuesVC.atmosphericPressureField.text = [NSString stringWithFormat:@"%@", vari[@"main"][@"pressure"]];
pointerToMoreValuesVC.windSpeedField.text = [NSString stringWithFormat:@"%@", vari[@"wind"][@"speed"]];
}