PFQuery将存储在PFObject中的数组中的对象加载到PFQueryTableViewController中

时间:2014-06-20 17:28:22

标签: ios parse-platform pfquery

我有PFQueryTableViewController加载Thread s(PFObjects与论坛帖子的数据)就好了。

当按下一个单元格时,新的PFQuertyTableViewController加载Response s(PFObjects,其中包含有关用户在线程上的响应的数据),但我无法确保它们是Response特定于Thread

我可以非常轻松地获得整个回复,

NSArray *responses = thread[@"responses"];

但是,我不知道如何在PFQuery中使用PFQueryTableViewController。这是我试过的:

我从this forum post得到了这个想法,但它对我没有任何作用(self.objects为空)。

- (PFQuery *)queryForTable
{
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    NSArray *threads = self.topic[@"threads"];
    for (PFObject *thread in threads)
    {
        [thread fetchIfNeeded];
        NSLog(@"Thread title: %@", thread[@"title"]);
    }
    [query whereKey:@"title" containedIn:threads];
    return query;
}

输出:

Thread title: This is my title for my post about "Animal Rights"
2014-06-20 10:25:11.730 ThumbWar[9185:60b] Fetched: <Thread:dasLkCUo77:(null)> {
    title = "This is my title for my post about \"Animal Rights\"";
    user = "<PFUser:********>";
}

1 个答案:

答案 0 :(得分:0)

在第一个PFQueryTableViewController中获得主题时使用includeKey。线程将带有响应,您可以在单击单元格时将这些响应传递给正常UITableViewController

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    [query includeKey:@"responses"]; //Retrieve responses of threads
    [query orderByDescending:@"createdAt"]; //You may also sort Threads if you want 
    return query;
}