IOS解析两个类Photo和Video的查询帮助

时间:2014-08-31 20:35:22

标签: ios objective-c parse-platform timeline

我更新解析和IOS,我正在尝试在时间轴中显示视频和照片。我正在扩展PFQueryTableViewController,并在queryForTable中尝试定义一个查询,以拉出当前用户所关注的用户发布的所有照片和视频,或者当前用户自己发布的帖子。我在查询时遇到问题,但这是我要做的事情:

parseClassName设置为Photo Class:

// self.parseClassName = @"Photo";

然后在queryForTable中:

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

PFQuery *followingActivitiesQuery = [PFQuery queryWithClassName:kFTActivityClassKey];
[followingActivitiesQuery whereKey:kFTActivityTypeKey equalTo:kFTActivityTypeFollow];
[followingActivitiesQuery whereKey:kFTActivityFromUserKey equalTo:[PFUser currentUser]];
followingActivitiesQuery.cachePolicy = kPFCachePolicyNetworkOnly;
followingActivitiesQuery.limit = 100;

PFQuery *photosFromFollowedUsersQuery = [PFQuery queryWithClassName:self.parseClassName];
[photosFromFollowedUsersQuery whereKey:kFTPhotoUserKey matchesKey:kFTActivityToUserKey inQuery:followingActivitiesQuery];
[photosFromFollowedUsersQuery whereKeyExists:kFTPhotoPictureKey];

/* Load videos from followed users
PFQuery *videosFromFollowedUsersQuery = [PFQuery queryWithClassName:self.parseClassName];
[videosFromFollowedUsersQuery whereKey:kFTVideoUserKey matchesKey:kFTActivityToUserKey inQuery:followingActivitiesQuery];
[videosFromFollowedUsersQuery whereKeyExists:kFTVideoKey];
*/
PFQuery *photosFromCurrentUserQuery = [PFQuery queryWithClassName:self.parseClassName];
[photosFromCurrentUserQuery whereKey:kFTPhotoUserKey equalTo:[PFUser currentUser]];
[photosFromCurrentUserQuery whereKeyExists:kFTPhotoPictureKey];

/* Load current users videos
PFQuery *videosFromCurrentUserQuery = [PFQuery queryWithClassName:self.parseClassName];
[videosFromCurrentUserQuery whereKey:kFTVideoUserKey equalTo:[PFUser currentUser]];
[videosFromCurrentUserQuery whereKeyExists:kFTVideoKey];
*/

PFQuery *query = [PFQuery orQueryWithSubqueries:[NSArray arrayWithObjects:photosFromFollowedUsersQuery, /*videosFromFollowedUsersQuery,*/
                                                                          photosFromCurrentUserQuery, /*videosFromCurrentUserQuery,*/ nil]];
[query includeKey:kFTPhotoUserKey];
/*[query includeKey:kFTVideoUserKey];*/
[query orderByDescending:@"createdAt"];

// A pull-to-refresh should always trigger a network request.
[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;
}

此代码可以在解析atypic示例中找到。

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

我最终通过将照片和视频解析类合并到一个" Post"类。