将 iOS Parse SDK 类与另一个类的对象进行比较 [英] Comparing iOS Parse SDK Class with another Class's objects
问题描述
所以我要做的基本上是在 UITableView 的每个单元格上添加一个按钮.我的 tableView 中的每个单元格都是在解析时从我的事件类填充的,其中每个对象都显示在一个新单元格中.
So what I'm trying to do essentially add a button next on each cell in my UITableView. Each cell in my tableView is being populated from my Event Class on parse where each object is displayed in a new cell.
一旦用户点击此按钮,它就会从他们点击的 Event 类中获取任何 Event 对象,并可能将其添加到 Parse 用户类中的属性"中,我将创建名为watching"的.
Once a user hits this button it takes whatever Event object from the Event class they've clicked and possibly adds it to a "property" in the Parse User Class I'll create named "watching".
但是,如果他们能够在用户类监视属性"下拥有所有这些事件,我将如何做这样的事情?我是否必须建立某种关系?
But how would I do something like this to where they're able to have all of these Events under the User Class "watching property"? Would I have to set up some relation of some sort?
总结:基本上,想要拥有一个监视列表,人们可以观看事件类中任何用户发布的任何对象.这些正在被监视的对象被添加到用户类中的一个属性中,以便我可以轻松地创建一个 UITableView 拉取当前用户正在监视的项目属性列表并显示它们.
Summary: Basically wanting to have a watch list people are able to watch any of the objects posted by any of the users in the Events Class. These objects that are being watched are added to a property in the User Class so that I can easily create a UITableView pulling the current users watching property list of items and displaying them.
推荐答案
您可以在 PFUser 类上创建一个字段:@"watching"
You could create a field on your PFUser class : @"watching"
然后将其用作数组,因此每当用户单击要观看的内容时...
Then use this as an array, so whenever the user clicks on something to watch ...
[[PFUser currentUser]addObject:objectToWatch.objectId forKey:@"watching"]; // adds it to the array
[[PFUser currentUser]save];
// something about arrays and parse objects, if you're using operations like "addObject" you should save or you'll get errors.
// the other option is to get an NSMutableArray from the array field, edit that, and reassociate it with the @"watching" key ... whichever you prefer
我们现在有一个与要观察的对象相关联的 Id 数组.你可以这样查询
We now have an array of Id's associated with objects to watch. You could query like so
PFQuery * query = [PFQuery queryWithClassName:@"ObjectsToWatch"];
[query whereKey:@"objectId" containedIn:[PFUser currentUser][@"watching"]];
[query findObjectsInBackground]; // use a block method though
这只是一种方法,希望对您有帮助
This is only one way to do it, hope it helps
这篇关于将 iOS Parse SDK 类与另一个类的对象进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!