这应该有用。
这是尝试解决这个问题的众多尝试之一
myTrainingSessions[indexPath.row].unpinInBackgroundWithBlock{ (succ, e) -> Void in
if succ == true {
// just remove from table view etc
self.myTrainingSessions[indexPath.row].deleteEventually()
self.myTrainingSessions.removeAtIndex(indexPath.row)
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
// Shows that my object is still in datastore!
// object should be UNPINNED - but appers in this result....
var query = PFQuery(className:TrainingSession.parseClassName())
query.whereKey(self.userType(), equalTo: PFUser.currentUser())
query.orderByDescending("createdAt")
query.fromLocalDatastore().ignoreACLs()
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error != nil { return }
if let result = objects as? [TrainingSession] {
println("local results")
println(result)
}
}
}
}
我在取消固定后进行查询,对象仍在那里。
答案 0 :(得分:3)
我已经联系过支持小组,了解了您无法解除具有引用对象的对象的问题,因此我会为感兴趣的人分享该主题:
https://developers.facebook.com/bugs/138298746504630/
支持人员称这是By Design,但根据我的要求改进此规范,他告诉我他会告诉团队。
答案 1 :(得分:2)
这对您不起作用的原因之一是因为您的本地数据存储区中可能仍有与您要取消固定的对象有关系的对象。要正确执行此操作,请先取消固定所有这些对象,然后取消固定目标对象。
答案 2 :(得分:1)
我使用了以下工作流程。
当我创建一个新对象并准备保存时,我会执行以下两个步骤
newThing.saveEventually(nil)
newThing.pinInBackgroundWithBlock { (res, errn) -> Void in
// pinning is required for offline delete to work correct
if errn != nil { return }
//self.presentingViewController?.dismissViewControllerAnimated(true, completion: { () -> Void in
// dismiss modal if required...
//})
}
在我的tableview中,我删除了这个
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
self.myDataSource[indexPath.row].deleteEventually()
self.myDataSource.removeAtIndex(indexPath.row)
self.myDataSource.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
在同一个tableview中获取进程
这是我的网络查询
func networkQuery() {
let nquery = theQuery()
nquery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let temp = objects as? [YourObjectType] where error == nil {
PFObject.unpinAllInBackground(self.myDataSource, block: { (resultBool, error) -> Void in
if error != nil { return }
PFObject.pinAllInBackground(temp, block: { (resultBool, error) -> Void in
if error != nil { return }
self.localQuery()
})
})
}
}
}
我试图打破这个创建新项目,在线和离线 - 删除项目在线和离线 - 所有工作。希望它有所帮助,无法在网上找到任何例子,所以只能用它来跟踪和错误....痛苦的过程,但现在就像一个魅力。
答案 3 :(得分:0)
做完R& D在parse.com上 我知道一旦将对象存储在云上,就可以从本地存储中取消对象。 B' coz parse主要用于在云上存储数据,因此它允许在云上存储后取消数据的固定。 例如
- (void)syncDataToCloud:(id)sender {
PFQuery *qry = [PFQuery queryWithClassName:@"Person"];
[qry fromLocalDatastore];
NSArray *arr = [qry findObjects];
[PFObject saveAllInBackground:arr block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
DisplayAlert(@"Sync successful.");
} else {
DisplayAlert(@"Sync unsuccessful");
}
}];
[PFObject unpinAll:arr];
}
它对我有用...... !! :)