

- (void)creatUrl {
NSString *urlString = [NSString stringWithFormat:@"https://v0.yiketianqi.com/api?unescape=1&version=v9&appid=27289148&appsecret=7HyJN1Ny&city=%@", _cityString];
//处理字符
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//创建URL
NSURL *url = [NSURL URLWithString:urlString];
NSURLSession *session1 = [NSURLSession sharedSession];
NSURLSessionTask *task1 = [session1 dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (!error) {
//解析数据
// NSInteger num = 0;
NSDictionary *secondDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSMutableArray *timeArray = [[NSMutableArray alloc] init];
timeArray = secondDictionary[@"data"];
self->_cityD = timeArray[0];
self->_city = timeArray;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self->_tableView reloadData];
}];
}
}];
[task1 resume];
}
NSDictionary *secondDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];timeArray = secondDictionary[@"data"];



- (void)pressSure {
int bool1 = 1;
NSLog(@"确定");
for (int i = 0; i < _returnArray.count; i ++) {
if ([_cityString isEqualToString:_returnArray[i]] ) {
bool1 = 0;
break;
}
}
if (bool1 == 0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"该城市添加过了" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
} else {
// 发送通知并回传数据
// 注册通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"inform" object:nil userInfo:_returnD];
[self dismissViewControllerAnimated:YES completion:nil];
}
// _returnArray = [NSMutableArray arrayWithObject:_cityString];
// [_delegate city1:_returnArray :num];
// [self dismissViewControllerAnimated:YES completion:nil];
}
// 注册观察者,用于接受界面二的通知,接收通知的名称必须和发送通知的名称保持一致才能收到
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receiveNoticed:) name:@"inform" object:nil];
// 观察者接受函数,
// 这里接受传值并赋值给当前页面的label
- (void)receiveNoticed:(NSNotification*)sender {
NSString* str = sender.userInfo[@"key1"];
[_cityArray addObject:str];
NSLog(@"newCitycount = %ld", _cityArray.count);
[_tableView reloadData];
}
// 移除通知
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}