Select a query for analysis before getting its value
I'm new to object c and I am using parse.com as my database for my social media app. What I am trying to do is grab the user's post from my POST table. I am using pointers to get the username from my USER table and this goes through a fine as you will see in my code posted below, but when I use fetchifneeded before assigning the UILabel to the user post, I get this error so far "Key History has no data. Call fetchIfNeeded before retrieving its value. I appreciate any help and thank you in an advanced way, if I don't make it so that I don't understand myself, all the more happy to expand something.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
if (indexPath.section == self.objects.count) {
UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
return cell;
}
static NSString *CellIdentifier = @"StoryCell";
NinetiesCell *cell = (NinetiesCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//for the post of the user
PFObject *user = object[@"User"];
[user fetchIfNeeded];
//get username from pointer
cell.userName.text = user[@"username"];
PFObject *story = [object objectForKey:@"Story"];
[story fetchIfNeeded];
cell.story.text = [object objectForKey:@"Story"];
// Configure the cell
NSDate *updated = [object createdAt];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
cell.dateLabel.text = [NSString stringWithFormat:@"%@", [dateFormat stringFromDate:updated]];
return cell;
}
source to share
The best option in your case would be to modify the original query to include the "User" and "History" columns, for example.
[query includeKey:@"User"];
[query includeKey:@"Story"];
Then when you reference those columns in tableView:cellForRowAtIndexPath:
, they will already be populated, no need to call fetchIfNeeded
.
source to share