显示uitableview单元格中的项目评级 [英] Show ratings of item in uitableview cell

查看:114
本文介绍了显示uitableview单元格中的项目评级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个iOS应用程序,在UITableView中显示30个菜单项,然后用户可以在详细页面上的5个开始中对这些项目进行评级,当用户点击单元格时会显示这些项目。

I am currently working on a iOS app that shows 30 menu items in a UITableView and Users can then rate theses items out of 5 starts on the detail page which is shown when a user taps the cell.

现在单元格中只是项目的标题,现在我要做的是拥有项目的标题和当前的平均值。标题下方项目的评级。现在我知道如何创建单元格,但是我无法以有效的方式获取当前电影评级的数据。

Now in the cell currently is just the title of the item, now what I want to do is have the title of the item and the current avg. rating of the item below the title. Now I know how to create the cell, but I am having trouble getting the data of the current rating of the movie in a efficient way.

我目前正在使用Parse。 com作为我的后端。现在,当用户提交评级时,它会被保存到我的Parse称为评级的班级。并且保存了项目的标题和给定的星星数量。

I am currently using Parse.com as my back-end. Now when a user submits a rating it is saved to my class on Parse called Ratings. And the title of the item and the number of stars given is saved.

现在我想到了获得平均星数的最有效方法item并将其放在UITableViewCell中。首先,我想到只执行一个可以查询所有30个项目的云代码函数,并且平均评级就像在parse.com docs中做的那样 https://parse.com/docs/cloud_code_guide#functions

Now I am trying to think of the most efficient way to get the average number of stars for the item and put it in the UITableViewCell. First I thought about just performing a cloud code function that would query all 30 item, and average the ratings like is done in the parse.com docs https://parse.com/docs/cloud_code_guide#functions.

这里的问题是有30个或更多项目,然后每个查询使用一个API请求,然后快速起来。所以我排除了这个选择。另一种方法是一次只显示5个项目然后在用户向下滚动时加载下一个项目,但是用户通常会非常快速地滚动浏览多个项目并仍然会查看菜单上的所有30个项目,因此无法解决我的问题。

The problem here is that there are 30 or more items and each query then uses an API request which, then gets up high pretty quick. So I have ruled out that option. Another would be to only display 5 items at a time and then load then next 5 when the user scrolls down, but users typically scroll through multiple items very quickly and would still look at all 30 items on the menu, so that doesn't solve my problem.

现在我也有自己的服务器,我目前存储了一些正在服务的项目。我在想是否有办法制作xml文件或JSON,当用户保存项目时我将其保存到Parse。然后还保存它这个文件。

Now I also have my own server where I currently store some of the items being served. I was thinking if there is a way to make an xml file, or JSON, and when a user saves an item I save it to Parse. And then also save it this file.

所以这就是我的想法以及我遇到的问题。我会使用Parse.com Javascript SDK制作一个Cloud Code Job,它每天运行一次。我会让这个函数预先形成一个查询,检索在最后一天保存到我的评级类的所有评级。这会给我所有的对象。现在,这就是我遇到的问题:如何从Parse.com SDK将此文件存入我的服务器,如何将新的评级保存到此文件?

So here is what I am thinking and where I get stuck. I would make a Cloud Code Job, using the Parse.com Javascript SDK, and it would run once a day. And I would have this function preform one query the retrieves all the ratings that were saved to my Ratings class in the last day. And this would give me all the objects. Now this is where I get stuck: how do I get this file onto my server from the Parse.com SDK and how do I just save the new ratings, to this file?

当然,我欢迎所有其他方法来解决这个问题,并尽量减少我的API请求。我在想也可能使用Parse.com托管来托管xml或JSON文件?

Of course I am open to all other suggestions of ways to get around this and minimize my API requests. I was thinking also possibly use the Parse.com hosting to host the xml or JSON file?

或者只是一种完全不同的方式来做,我没有提到。

Or just a completely different way to do it, that I haven't mentioned.

我知道这是一个很长的问题,我尽力解释,如果您有任何疑问,请询问。

I know this is a long question, and I did my best to explain it, if you have any question please ask.

提前感谢您的帮助。我真的很感激:)

Thanks for the help in advance. I really appreciate it :)

编辑

我忘记提及的是这些物品每天都在变化,我有多家餐厅,每个都有自己的物品,所以这是30 *#的餐厅。因此,当我显示时,可以在表视图中说出30个项目我不知道如何在两个查询中获得所有评级(使用额外的类,我是否还需要查询每个项目)?

Something I forgot to mention is that these items change daily, and I have multiple restaurants each with their own items, so it's 30 * # of restaurants. So when I am displaying lets say 30 items in the table view Im not sure how I get all the ratings in two queries (with the extra class, don't I still need to query for each item)?

编辑2

好的,现在我有一个NSMutableArray充满评级,我从我的疑问。但是让我说我​​的表视图中有一个,两个和三个的项目。并且只评价了一个和三个,然后我得到了这些项目的两个评级,如果在我的 cellForRowAtIndexPath:方法中,我就这么做了。类似

Okay so now I have an NSMutableArray filled with the ratings, that I get returned from my query. But lets say I have the items "one", "two" and "three" in my table view. And only "one" and "three" have been rated, then I get the two ratings back for those items, and if in my cellForRowAtIndexPath: method I just do. something like

cell.rating = ratingsArray[indexRow.path];

然后第二项将有三分之一评级......

Then the item two will have what should be threes rating...

你看到了问题吗?我怎么能绕过它?

Do you see the problem? And how I could get around it?

谢谢

推荐答案

为什么不只是有两个属性。 allStars和numboerOfReviews。每次有人撰写评论时,

Why not just have two properties. allStars and numboerOfReviews. Each time someone writes a review,

[电影incrementKeyallStars由用户选择]

[movie incrementKey:numberOfReviewsbyAmount:1]

然后处理avg客户端。 allStars / numberOrReviews

Then handle avg client side. allStars/numberOrReviews

这些应该是MovieObject上的属性,当您查询电影时它们将被包含在内,因为它们是基元而不是指针。因此,当您执行PFQuery时,如果成功,您将获得一个PFObject数组。将tableViewDataArray设置为查询返回的数组。然后在cellForRowAtIndexPath中,您可以访问属性,例如(tableViewDataArray [indexPath.row] as Movie).numberOfStars

These should be properties on your MovieObject, and they will be included when you query the movies, since they are primitives and not pointers. So when you perform a PFQuery, if successful, you get an array of PFObjects. Set you tableViewDataArray to the array your query returns. Then in cellForRowAtIndexPath, you access you properties, like (tableViewDataArray[indexPath.row] as Movie).numberOfStars

这篇关于显示uitableview单元格中的项目评级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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