gpt4 book ai didi

ios - 从 Parse.com 的数据库中删除项目(iOS App)

转载 作者:行者123 更新时间:2023-11-29 02:40:01 26 4
gpt4 key购买 nike

我正在为我的 iOS 应用程序使用 Parse.com 8 ...在解析数据库中,我创建了一个名为“Relationships”的新类,我想做的是为我的应用程序的用户添加前缀,以向另一个用户发送好友请求。我没有使用 PFRelation,因为我需要好友请求不是自动的,而是被用户接受的。

简而言之,用户发送了一个请求 richeista of friendship 并且在订阅者不接受该请求之前,该请求将保留在状态为“等待”的“关系”类中。

现在我可以做我能做的一切了:

  • 注册两者的用户指针(接收者和转发者的好友请求)
  • 插入请求状态“待处理”

我的问题是,如果我的用户不想更多“发送请求不能”删除..

我尝试使用 ["name of PFObject"deleteInBackground] 但我无法删除任何内容......

你能帮我弄清楚如何从数据库中删除新创建的数据来解析吗?

#pragma mark ADD FRIENDS
-(void)addFriendUserButtonPressed:(UITableViewCell *)customCell {


NSIndexPath *indexPath = [self.tableViewFindUser indexPathForCell:customCell];

PFObject *richiesta = [PFObject objectWithClassName:@"Relation"];

if (!isFiltered) {

PFUser *userFiltered = [self.userArray objectAtIndex:indexPath.row];

if (![self Is_InAttesa:userFiltered]) {


[richiesta setObject:userFiltered forKey:@"To_User"];
[richiesta setObject:[PFUser currentUser] forKey:@"From_User"];
[richiesta setObject:@"Pending" forKey:@"STATUS"];
[richiesta saveInBackground];



} else {


//[richiesta removeObject:[PFUser currentUser] forKey:@"From_User"];
//[richiesta setObject:userFiltered forKey:@"STATUS"];
//[richiesta saveInBackground];
}



}

else {

PFUser *userNotFiltered = [self.userFiltrati objectAtIndex:indexPath.row];


[richiesta setObject:userNotFiltered forKey:@"To_User"];
[richiesta setObject:[PFUser currentUser] forKey:@"From_User"];
[richiesta setObject:@"Pending" forKey:@"STATUS"];
[richiesta saveInBackground];

}


}

这是我创建的 bool 方法,用于识别(通过查询)用户是否出现在待处理好友请求列表中

-(BOOL)Is_InAttesa:(PFUser *)user_inattesa {
for (PFUser *userInAttesa in amiciInAttesaMutableArray) {
if ([[[userInAttesa objectForKey:@"To_User"]objectId] isEqualToString:user_inattesa.objectId]) {
return YES;
}
}
return NO;
}

enter image description here

最佳答案

这是一个从解析中删除对象的方法。

-(void)deleteButton {

//Query or retrieving data from dB which you want to delete.
PFQuery *query = [PFQuery queryWithClassName:@"YOUR_CLASS"];

//This string in below case takes name from textfield that user wants to delete. For your case you could modify it as per your need.
NSString *receiver_idStr =@"Id";
NSString *sender_idStr =@"Id";

// below two queries will work as like SELECT * FROM someTable WHERE senderId = 'id' AND receiverId = 'id'
[query whereKey:@"request_sender_id" containsString:sender_idStr];
[query whereKey:@"request_receiver_id" containsString:receiver_idStr];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { //Query fired in background to search in parse for this object with condition provided.

if (!error) {
NSLog(@"Successfully retrieved: %@", objects);

//Now as you got object then you will type cast object from NSArray to PFObject and perform deleteInBackground method on them.

//Also update that UI part ,i.e., remove the request object from UI.
}
else {
NSLog(@"Error: %@", [error localizedDescription]);
}
}];
}

所以这种方式将能够从解析中删除请求对象。此外,当发送请求的用户取消请求时,您也会搜索该请求对象并在接收请求的用户的其他地方执行相同操作,您可以推送通知以从其 UI 中删除该请求。

如果用户收到删除请求,那么只需找到请求对象并删除,然后更新发送者和接收者的 UI。

关于ios - 从 Parse.com 的数据库中删除项目(iOS App),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25908725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com