I have a UITableViewController that is responsible for displaying a table full of employees. This data is stored in a database at parse.com.
This is my UITableViewController in which I just start the repository:
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nil bundle:nil]; if(self){ store = [[EmployeeStore alloc] init]; } return self; }
This is the EmployeeStore init method in which I request employees:
-(id) init{ self = [super init]; if(self){ employees = [[NSMutableArray alloc] init]; [self fetchEmployeesFromDatabase]; } return self; }
fetchEmployeesFromDatabase , where I request employees.
-(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]); } }]; }
I successfully receive them, however, the problem is that the query is executed in the background and does not end until it is loaded after viewing the table, so the table view is not filled. I need the table to reload its data after the query is complete, but how do I do this?
source share