Parse.com - 从第二个类/对象添加值

时间:2013-07-12 17:52:49

标签: ios parse-platform

所以我使用Parse.com和他们的AnyPic应用程序作为起点。这是一个Instagram克隆。但是,与Instagram不同,图片评论不包含在主页上。你必须点击图片,它会带来一个DetailsVC与通讯。这是我要改变的第一件事。

我是Parse的新手(以及一般的后端),我在尝试修改查询以返回评论时遇到问题。如果您使用过AnyPic,则表示评论未保存在Photo类中,而是保存在单独的Activity类中:

enter image description here

Activity.type等于commentActivity.content将成为评论文字。


所以,AnyPic中的VC子类Parse的PFQueryTableViewController,覆盖了queryForTable方法来获取数据。这是他们的AccountVC的queryForTable,它只返回照片:

- (PFQuery *)queryForTable {
    if (!self.user) {
        PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
        [query setLimit:0];
        return query;
    }

    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    query.cachePolicy = kPFCachePolicyNetworkOnly;
    if (self.objects.count == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }
    [query whereKey:kPAPPhotoUserKey equalTo:self.user];
    [query orderByDescending:@"createdAt"];
    [query includeKey:kPAPPhotoUserKey];

    return query;
}

DetailsVC的queryForTable,它将返回self.photo中传递给它的照片对象的评论:

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    [query whereKey:kPAPActivityPhotoKey equalTo:self.photo];
    [query includeKey:kPAPActivityFromUserKey];
    [query whereKey:kPAPActivityTypeKey equalTo:kPAPActivityTypeComment];
    [query orderByAscending:@"createdAt"]; 

    [query setCachePolicy:kPFCachePolicyNetworkOnly];

    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    //
    // If there is no network connection, we will hit the cache first.
    if (self.objects.count == 0 || ![[UIApplication sharedApplication].delegate performSelector:@selector(isParseReachable)]) {
        [query setCachePolicy:kPFCachePolicyCacheThenNetwork];
    }

    return query;
}

我无法理解如何将两个查询合并为一个并让它返回附加了注释值的照片对象。

我曾想过在tableView:numberOfRowsInSection:返回一组照片时,只为queryForTable中的评论运行单独的查询,但我认为如果我让Parse的queryForTable更好处理它,以防有一些可能有用的缓存。

0 个答案:

没有答案