Reputation:
I am loading data into an NSArray to help populate my table view.
(void)viewDidLoad
{
[super viewDidLoad];
PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Successfully retrieved %d videos.", objects.count);
for (PFObject *object in objects) {
NSArray *videos = [NSArray arrayWithObjects:object, nil];
NSLog(@"Video Details: %@", videos);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
[self.tableView reloadData];
Details for an individual video looks something like this:
"<UserPhoto:ifb0vYa8x6:(null)> {\n ACL = \"<PFACL: 0xb3645a0>\";\n imageFile = \"<PFFile: 0xb2d8ef0>\";\n title = \"\";\n user = \"<PFUser:zEwPBaCg7x>\";\n}"
I am then trying to grab the objectForKey of @"title" and load it into my UITableViewCell label but it doesn't seem to work:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [recipes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableViews cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *recipeNameLabel = (UILabel *)[cell viewWithTag:101];
recipeNameLabel.text = [[recipes objectAtIndex:indexPath.row ] objectForKey:@"title"];
return cell;
}
My label "recipeNameLabel" is not holding any data for the title. Does anyone know what is wrong?
Upvotes: 0
Views: 94
Reputation: 119031
You don't say what is wrong / observed, but findObjectsInBackgroundWithBlock:
is an asynchronous call so you should be calling [self.tableView reloadData];
is the callback block, not after the method call (which will actually run before the callback completes).
At the moment you reload the table before you have any data to display.
Also, looking at your object log, title = \"\";
means that the title is an empty string...
Upvotes: 1