PFQueryTableViewController具有3个部分 [英] PFQueryTableViewController with 3 Sections

查看:75
本文介绍了PFQueryTableViewController具有3个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解析数据库中有一个游戏"表,其中包含以下相关列:

I have a 'Game' table in my parse database with the following relevant columns:

  • isOver(布尔值)
  • whoseTurn(关系:_User)(游戏可以有多个玩家,因此一次可以有一个人以上的回合)
  • 玩家(关系:_User)

我需要查询该表并将结果显示在tableview的3个单独的部分中:

I need to query this table and display the results in 3 separate sections of the tableview:

  • 轮到我了"
  • 轮到他们了"
  • 游戏结束"

我正在考虑将以下查询与此处给出的答案中的某些代码结合使用: https://parse.com/questions/using-pfquerytableviewcontroller-for-uitableview-sections

I was thinking of using the following query coupled with some of the code in the answer given here: https://parse.com/questions/using-pfquerytableviewcontroller-for-uitableview-sections

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

    [query whereKey:@"players" equalTo:[PFUser currentUser]];

    //BREAK UP INTO SECTIONS
    [query orderByDescending:@"isOver"];
    [query addDescendingOrder:@"whoseTurn"];

如何在3个不同的Tableview部分中显示结果?

How can I display the results in 3 different tableview sections?

推荐答案

该问题包含两个挑战,对于PFQueryTableVC来说这是一个太多的挑战.您在网站上发布的帖子清楚地表明,您可以获得带有一些额外覆盖的部分,但其中没有涵盖的是您的模型通过PFRelation依赖于相关对象(用户).

The question contains two challenges, and that's one too many for the PFQueryTableVC. The post you site makes evident that you can get sections with a little extra overriding, but what's not covered there is that your model depends on related objects (users) via a PFRelation.

该额外要求排除了PFQueryTableVC,因为它假定您的表可以在单个查询中获取,但是您的表取决于获取这两个关系列.

That extra requirement rules out the PFQueryTableVC because it assumes your table can be fetched in a single query, but yours depends on fetching those two relations columns.

这将迫使您使用普通的UIViewController滚动自己的视图,而该UIViewController具有UITableView作为其视图的子视图. (请注意,我不建议在这里使用UITableViewController ...就像PFQueryTableVC一样,虽然通常可以在这里省掉很多精力,但它通常会带来更多的麻烦).

This is going to force you to roll your own with a plain old UIViewController that has a UITableView as its view's subview. (Notice I don't recommend UITableViewController here... just like PFQueryTableVC, it often generates more effort than convenience, though you could probably get away with it here).

操作方法的要点是:依次查询游戏表,然后是whoseTurn关系,然后是players关系.有了这些数据,您就可以将找到的游戏分为三个数组,分别与您的表视图部分完全对应:gamesThatAreOvergamesThatAreUsersTurngamesThatAreOtherUsersTurn.

The gist of how to do it is this: in succession, query the games table, then it's whoseTurn relation, then it's players relation. With that data, you'll be able to segregate the found games into three arrays, corresponding exactly to your table view sections: gamesThatAreOver, gamesThatAreUsersTurn, gamesThatAreOtherUsersTurn.

您可以将这些数组放在另一个数组中,将其称为model.告诉表视图您有self.model.count个部分(始终为==3),并且索引路径的行数为self.model[indexPath.section].count

You can put those arrays in another, call it model. Tell your table view that you have self.model.count sections (that will always be ==3), and that the number of rows at an index path is self.model[indexPath.section].count

您在索引路径处的对象版本将为您提供游戏,并且外观如下:self.model[indexPath.section][indexPath.row];

Your version of object at index path will give you a game, and will look like this: self.model[indexPath.section][indexPath.row];

PS-我认为,从提供类的解析的便利性"(又称约束)中解放出来,无论如何将是一种净积极的态度.

PS - I think freeing yourself from the "convenience" (aka constraint) of the parse provided class is going to be a net positive anyway.

这篇关于PFQueryTableViewController具有3个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆