简体   繁体   English

使用Relation Parse.com保存对象而不是PFUser CurrentUser

[英]Saving Object With Relation Parse.com not PFUser CurrentUser

I'm working with Parse.com ... My app relies heavily on relations between users and to use this thing PFRelation that creates a relationship between the User and the User corrent selected ... 我正在使用Parse.com ...我的应用程序在很大程度上依赖于用户之间的关系,并使用这个事物PFRelation,创建用户和用户之间的关系选择...

Whenever the Current User chooses User " A" creates the relationship with PFRelation and User "A" receives a push notification where it is informed that the current user has started to follow him. 每当当前用户选择用户“A”创建与PFRelation的关系时,用户“A”接收推送通知,其中通知当前用户已经开始跟随他。

Now I have created through a label , even the badge number that should appear not to CurrentUser but the USER "A" that receives the notification . 现在我已经创建了一个标签,甚至是不应该出现在CurrentUser上的徽章编号,而是收到通知的USER“A”。 The badge I'm talking about is NOT the classic Icon badge but it is a badge that appears on NavigationBar . 我正在谈论的徽章不是经典的Icon徽章,但它是出现在NavigationBar上的徽章。

To do all this I should try to save an entry in the special class _USER CurrentUser but not to the USER "A" .. Could you tell me how could I do? 要做到这一切,我应该尝试在特殊类_USER CurrentUser中保存一个条目,但不能保存到用户“A”的条目..你能告诉我怎么办? I already have an array fetches the names of users and displays them in tablebiew . 我已经有一个数组获取用户名并在tablebiew中显示它们。

For example, to create the relationship with the user selected on the Tableview I implemented a PFUser connected with the array 例如,要创建与Tableview上选择的用户的关系,我实现了与阵列连接的PFUser

- (void) tableView : ( UITableView * ) tableView didSelectRowAtIndexPath : ( NSIndexPath * ) indexPath {
[ self.TableView deselectRowAtIndexPath : indexPath animated : NO] ;
    
if (! isFiltered ) {

    UITableViewCell * cell = [ self.TableView cellForRowAtIndexPath : indexPath ] ;
    cell.accessoryType = UITableViewCellAccessoryCheckmark ;

    PFUser * user = [ self.Utenti objectAtIndex : indexPath.row ] ;
    PFRelation * Report = [ [ PFUser currentUser ] relationforKey : @ "Relationship "] ;
    PFInstallation currentInstallation * = [ PFInstallation currentInstallation ] ;
    NSString * RegistraNomeUtente = [ NSString stringWithFormat : @ "% @ " , [user objectForKey : FF_USER_NOMECOGNOME ]] ;
 
.....

Basically you create a new class on parse named such as Activity . 基本上你在一个名为Activity parse上创建一个新类。 From this class, you will have from_user attribute is a pointer to User class and to_user is also a pointer to User class. 从这个类中,你将拥有from_user属性是指向User类的指针,而to_user也是指向User类的指针。 Maybe you can have one more attribute name type used to indicate what type of relationship betweens users. 也许您可以再使用一个属性名称type来指示用户之间的关系类型。 Each user can "follow", "post comment", "like" each other. 每个用户可以“跟随”,“发表评论”,“喜欢”彼此。

Now get back to your code. 现在回到你的代码。 I assume that you will have a particular PFUser object when you click on a specific row of your tableView. 我假设当您单击tableView的特定行时,您将拥有特定的PFUser对象。 In -tableView:didSelectRowAtIndexPath: you save new Activity object by using the following pseudo code: -tableView:didSelectRowAtIndexPath:使用以下伪代码保存新的Activity对象:

PFObject *activityObj = [PFObject objectWithClassName:@"Activity"];
[activityObj setObject:[PFUser currentUser] forKey:@"from_user"];
[activityObj setObject:OtherUserObj forKey:@"to_user"];
[activityObj setObject:@"follow" forKey:@"type"];
[activityObj saveInBackGround];

Now you have a relationship between current user and other user. 现在,您在当前用户和其他用户之间建立了关系。 You can get total number of following user to display in your badge item by: 您可以通过以下方式获取要在徽章项中显示的以下用户的总数:

PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activity"];
[activityQuery whereKey:@"from_user" equalTo:[PFUser currentUser]];
[activityQuery whereKey:@"type" equalTo:@"follow"]];
[activityQuery countObjectsInBackground];

Hope it helps you :) 希望它能帮到你:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM