I'm using Parse.com's solution for databases, and want to load db-table into a UITable. I'm trying to accomplish this by first creating an array, then loading the database-table into that array, and finally loading the array into the UITable.
However, nothing is shown in the UITable.
Could this be because the database does not have time to be retrieved before the "cellForRowAtIndexPath" is called (and thus is empty when cycling trough and setting up each cell)?
Or is my syntax wrong?
Alternatively, is there a better way of doing this?
Code:
- (void)setupArray
{
dummyArray = [[NSMutableArray alloc] init];
PFQuery *query = [PFQuery queryWithClassName:@"Events"];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
for (PFObject *comment in comments)
{
PFObject *post = [comment objectForKey:@"event"];
[dummyArray addObject:post];
}
}];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [dummyArray objectAtIndex:indexPath.row];
return cell;
}
However, nothing is shown in the UITable.
Could this be because the database does not have time to be retrieved before the "cellForRowAtIndexPath" is called (and thus is empty when cycling trough and setting up each cell)?
Or is my syntax wrong?
Alternatively, is there a better way of doing this?