我有一个UITableViewController
负责展示一张满是员工的桌子。此数据存储在 parse.com 上的数据库中。
这是我UITableViewController
的,我只是在其中启动商店:
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nil bundle:nil];
if(self){
store = [[EmployeeStore alloc] init];
}
return self;
}
这是EmployeeStore
init 方法,我在其中查询员工:
-(id) init{
self = [super init];
if(self){
employees = [[NSMutableArray alloc] init];
[self fetchEmployeesFromDatabase];
}
return self;
}
fetchEmployeesFromDatabase
,我在其中查询员工。
-(void) fetchEmployeesFromDatabase{
PFQuery *query = [PFQuery queryWithClassName:@"Employee"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d scores.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
[employees addObject:object];
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
我已成功接收它们,但问题是查询发生在后台,并且在表视图加载完成后才完成,因此表视图不会填充。查询完成后,我需要让表重新加载其数据,但我该怎么做呢?