我有一个表视图,其内容是用 json 数组生成的。它还使用位置服务,以便在用户位置发生变化时,重新加载表以反映表数据相对于用户位置的变化。
我的问题是我在视图加载开始时显示活动指示器,但每次位置更新和表重新加载时,都会显示指示器。这是在很短的时间间隔内完成的,导致应用程序崩溃。
是否可以在下面的代码中设置一个条件,以便它不会显示 MBProgressHUD 如果它不是初始加载但它是由位置更改引起的重新加载?
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
return [rows count];
}
这是执行重新加载的地方:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *lat = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longt = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
//CGFloat Alat = [lat floatValue];
//CGFloat Alon = [longt floatValue];
self.aalat = lat;
self.aalon = longt;
// NSLog(@"anlat: %@", aalat);
// NSLog(@"anlong: %@", aalon);
[[NSUserDefaults standardUserDefaults] setObject:aalat forKey:@"latitude"];
[[NSUserDefaults standardUserDefaults] setObject:aalon forKey:@"longitude"];
[tableview reloadData];
}