Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 条件执行_Iphone_Xcode_Conditional_Mbprogresshud - Fatal编程技术网

Iphone 条件执行

Iphone 条件执行,iphone,xcode,conditional,mbprogresshud,Iphone,Xcode,Conditional,Mbprogresshud,我有一个tableview,它的内容是用json数组生成的。它还使用位置服务,以便在用户位置发生更改时,重新加载表以反映表数据相对于用户位置的更改 我的问题是,我在视图加载的开头显示活动指示器,但每次位置更新和表重新加载时,都会显示该指示器。这在很短的时间间隔内完成,导致应用程序崩溃 是否有可能在以下代码中添加一个条件,使其在不是初始加载但存在由位置更改引起的重新加载时不会显示MBProgressHUD // Customize the number of rows in the table v

我有一个tableview,它的内容是用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];
}

我会从viewDidLoad或ViewWillAspect方法中触发HUD,以便最初加载内容。从tableview启动会给您带来很多问题。当用户滚动时,tableview方法会被反复激发,因此您总是会遇到这样的问题

从位置更新触发一个方法以显示HUD。它必须在主线程上运行,动画才能正常工作。我将从新方法调用重载表,以避免tableview出现任何问题