gpt4 book ai didi

ios - PFQuery includeKey 似乎不起作用 : Key data unavailible

转载 作者:行者123 更新时间:2023-11-29 10:32:37 25 4
gpt4 key购买 nike

我正在构建一个社交应用程序,目前正在构建一个 PFQueryTable View Controller ,我想为在上一个屏幕中选择的用户显示关注者列表。

在 queryForTable 下,我有以下查询集:

-(void) queryForTable {

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey:@"type" equalTo:@"follow"];
[query whereKey:@"fromUser" equalTo:self.user];
[query whereKey:@"toUser" notEqualTo:self.user];
[query whereKeyExists:@"toUser"];
[query includeKey:@"toUser"];
[query orderByDescending:@"createdAt"];

[query setCachePolicy:kPFCachePolicyNetworkOnly];

return query;

}

当我为 cellForRowAtIndexPath 下的对象执行 NSLog 时:

- (FollowViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *FollowCellIdentifier = @"FriendCell";

FollowViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FollowCellIdentifier];
if (cell == nil) {
cell = [[FollowViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FollowCellIdentifier];
}

NSLog(@"OBJECT IS %@",object);


cell.userLabel.text = [[object objectForKey:@"toUser"] objectForKey:@"username"];



return cell;
}

结果是

OBJECT IS { ACL = ""; fromUser = ""; toUser = ""; type = follow; }

如果我尝试创建:

cell.userLabel.text = [[object objectForKey:@"toUser"] objectForKey:@"username"];

控制台给我一个错误:

'Key "username" has no data. Call fetchIfNeeded before getting its value.'

如果我使用中断来逐步执行该过程,则 userLabel.text 会很好地填充。但是如果我不间断地运行它,我总是会得到错误。我在这里缺少什么吗?

任何帮助都会很棒,因为在过去的 4 天里我一直在努力解决这个问题。

最佳答案

尝试:

PFUser *user = (PFUser *)[object objectForKey:@"toUser"];
[user fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
cell.userLabel.text = [object objectForKey:@"username"];
}];

关于ios - PFQuery includeKey 似乎不起作用 : Key data unavailible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28854446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com