我想在重新加载数据之前删除表视图中的所有行,但似乎无法让它工作。
在我的视图控制器中,我从这个 AFNetworking 请求中获取了我的数组。
- (void)viewDidLoad
[[LocationApiClient sharedInstance] getPath:@"locations.json"
parameters:nil
success:
^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
NSMutableArray *location_results = [NSMutableArray array];
for (id locationDictionary in response) {
Location *location = [[Location alloc] initWithDictionary:locationDictionary];
[location_results addObject:location];
}
self.location_results = location_results;
[self.tableView reloadData];
}
failure:
^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching locations!");
NSLog(@"%@", error);
}];
}
我想删除数据然后用这个按钮重新加载它
- (IBAction)locationPressed:(id)sender {
[[Location sharedSingleton].locationManager startUpdatingLocation];
[self viewDidLoad];
NSMutableArray *location_results = [NSMutableArray array];
[location_results removeAllObjects];
[self.tableView reloadData];
}
但它不会删除行。我看到重新加载发生在已经存在的行的顶部。有什么建议么?