[英]Ios- Parse.com delete an object
我想我的情況太復雜了。 我正在處理多種情況下的聯接表。
如果我找到一個連接,我想刪除它,如果我找不到,我想添加它。
添加新連接工作正常。 我無法想象如何刪除..
這是我的代碼。 如果有人發現任何錯誤 - 或者更好的方法,請提供建議。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
//Create query for all current user objects
PFQuery *query = [PFQuery queryWithClassName:@"DDPeopleJoin"];
[query whereKey:@"parseUser" equalTo:[PFUser currentUser]];
[query whereKey:@"serviceKey" equalTo:[currentService valueForKey:@"serviceKey"]];
[query whereKey:@"personKey" equalTo:[currentPerson valueForKey:@"personKey"]];
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
// Run the query - if there is an object delete it otherwise, go to JoinPeople
allDeadPeople = [NSMutableArray new];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
if (!objects) {
NSLog(@"New Person");
[self joinPeople];
return;
}
NSLog(@"Found a match, erase them");
for (PFObject *object in objects) {
[object deleteInBackground];
}
[self refreshJoins:self];
}
}];
}
首先,您可以使用以下內容,而不是使用枚舉塊來刪除每個對象:
[PFObject deleteAllInBackground:objects];
其次,你可能會遇到麻煩[self refreshJoins:self
coz它將在所有object
被刪除之前運行。 你應該把它放在-deleteInBackground:block
以確保[self refreshJoins:self]`正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.