将iOS Parse SDK类与另一个类的对象进行比较。

时间:2020-11-24 21:22:42

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.

我要做的是在UITableView中,在每个单元格上添加一个按钮。我的tableView中的每个单元格都是从我的事件类中填充的,在解析中,每个对象都显示在一个新单元中。

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".

一旦用户点击这个按钮,它就会从事件类中获取任何事件对象,并可能将其添加到解析user类中的“属性”中,我将创建“监视”。

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?

但是,我该如何做这样的事情呢?在用户类的“监视属性”下,它们能够拥有所有这些事件吗?我需要建立某种关系吗?

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.

概要:基本想要有一个观察列表,人们可以观看任何一个用户在事件类发布的对象。这些正在被监视的对象被添加到User类中的一个属性中,这样我就可以轻松地创建一个UITableView,让当前用户查看项目的属性列表并显示它们。

2 个解决方案

#1


0  

I hope I have understood what you want ... If I understand it you need a form of relationship between the object and the CurrentUser viewing it ...

我希望我已经明白你想要的……如果我理解了,你需要一种对象和CurrentUser之间的关系形式。

normally to identify the selected cell within a IBAction you can 'use this method:

通常,要在IBAction中识别所选的单元,您可以“使用此方法:

- (IBAction) button: (id) sender {

NSIndexPath * indexPath = [self.TableView indexPathForSelectedRow];
PFObject SelectedObject * = [self.YOUR_ARRAY objectAtIndex: indexPath.row];

}

This way you've identified which cell the current user has selected .. From this point on, continue with the PFObject to save the data the way you want

通过这种方式,您可以确定当前用户选择了哪个单元格。从这一点开始,继续使用PFObject,以您想要的方式保存数据。

The essential thing is to set the goal of PFObject (in this case the selected cell) then continues to set the data to be set according to what you need

最重要的是设置PFObject的目标(在本例中是选中的单元格),然后继续根据需要设置数据。

#2


0  

You could create a field on your PFUser class : @"watching"

您可以在PFUser类上创建一个字段:@“监视”

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

We now have an array of Id's associated with objects to watch. You could query like so

我们现在有了一个Id的数组,它与要观察的对象关联。您可以这样查询。

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

这只是一种方法,希望它能有所帮助。

#1


0  

I hope I have understood what you want ... If I understand it you need a form of relationship between the object and the CurrentUser viewing it ...

我希望我已经明白你想要的……如果我理解了,你需要一种对象和CurrentUser之间的关系形式。

normally to identify the selected cell within a IBAction you can 'use this method:

通常,要在IBAction中识别所选的单元,您可以“使用此方法:

- (IBAction) button: (id) sender {

NSIndexPath * indexPath = [self.TableView indexPathForSelectedRow];
PFObject SelectedObject * = [self.YOUR_ARRAY objectAtIndex: indexPath.row];

}

This way you've identified which cell the current user has selected .. From this point on, continue with the PFObject to save the data the way you want

通过这种方式,您可以确定当前用户选择了哪个单元格。从这一点开始,继续使用PFObject,以您想要的方式保存数据。

The essential thing is to set the goal of PFObject (in this case the selected cell) then continues to set the data to be set according to what you need

最重要的是设置PFObject的目标(在本例中是选中的单元格),然后继续根据需要设置数据。

#2


0  

You could create a field on your PFUser class : @"watching"

您可以在PFUser类上创建一个字段:@“监视”

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

We now have an array of Id's associated with objects to watch. You could query like so

我们现在有了一个Id的数组,它与要观察的对象关联。您可以这样查询。

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

这只是一种方法,希望它能有所帮助。