2014-02-16 33 views
0

我有一个表的解析与列当查询解析指针 - 它返回零

的ObjectId |邀请者(指针)|活动(布尔)| createdAt(date)

我想用Inviter信息填充表格。所以我试图在查询期间拉指针。

下面是拉动该数据

- (void) getInvitationsForLoggedInUser { 
    NSLog(@"entered getInvitationsForLoggedInUser"); 
    PFQuery *postQuery = [PFQuery queryWithClassName:@"Connection"]; 
    [postQuery whereKey:@"Active" equalTo:[NSNumber numberWithBool:NO]]; 
    [postQuery includeKey:@"Inviter"]; 

    [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) { 
      [self.tableData addObjectsFromArray:objects]; 
      NSLog(@"InvitationViewController - Loaded %lu connection objects from Parse for logged in user", (unsigned long)[objects count]); 
      [self.invitationTableView reloadData]; 
     } else { 
      NSLog(@"InvitationViewController - Could not find any connection objects from Parse"); 
     } 
    }]; 
} 

这里就是我打电话从资料表阵列数据的方法。

- (InvitationCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    //TOFIX: In the view, I am seeing the entry but the fields are null. Need to check that the cell fields are getting populated. 

    static NSString *cellIdentifier = @"Identifier"; 
    InvitationCell *cell = (InvitationCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    // Create a new PFObject Object 
    PFObject *connection = nil; 

    connection = [self.tableData objectAtIndex:[indexPath row]]; 

    PFObject *inviterCodeName = [connection objectForKey:@"Inviter"]; 
    if (inviterCodeName == nil) { 
     NSLog(@"Error: Could not retrieve 'Inviter' object from connection object with id %@", [connection objectId]); 
    } 

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; 
    [dateFormatter setLocale:enUSPOSIXLocale]; 
    [dateFormatter setDateFormat:@"EEE, MMM, h:mm a"]; 

    cell.dateLabel.text = [dateFormatter stringFromDate:[connection updatedAt]]; 

    cell.codeName.text = [NSString stringWithFormat:@"Inviter Code Name: %@", inviterCodeName[@"codeName"]]; 
    if (inviterCodeName[@"description"] == nil) { 
     cell.codeNameDescription.text = @""; 
    } else { 
     cell.codeNameDescription.text = [NSString stringWithFormat:@"%@", inviterCodeName[@"description"]]; 
    } 

    return cell; 
} 

只是为了保持完整性, 这些在这个生命周期方法

- (void) viewWillAppear:(BOOL)animated { 
    [self getInvitationsForLoggedInUser]; 
    [super viewWillAppear:animated]; 
    [self.invitationTableView reloadData]; 
} 

都叫做现在,在的cellForRowAtIndexPath,我成功地获取了Connection对象。当我尝试获取“inviterCodeName”对象时,它始终为零。

在我测试这个时,我只在表中有一行符合这些要求,并且它已成功填充。

有什么建议吗?

+0

什么意思?“我在测试时只满足这些要求中的一行,并且它已成功填充。”?另外,''viewWillAppear'方法中的'[self.invitationTableView reloadData];'可能会在'findObjectsInBackgroundWithBlock'完成之前调用(即没有数据,所以不要更新表)。 – bobnoble

+0

我在表中有一行正在查询以符合标准。让我尝试将reloadData移出viewWillAppear – envinyater

+0

不幸的是: – envinyater

回答

0

这似乎是一个异步问题。该表在后台解析线程返回数据之前加载。我将呼叫切换为同步。

我不是100%确定这是“正确”的方式,但它确实解决了问题。