[英]Parse + iOS: 101 error when saving after a delete operation
在我的iOS應用中,我有一個PFQueryCollectionViewController
,它顯示UserPhoto對象。 在收藏夾視圖單元上輕按可打開照片詳細信息頁面,用戶可在其中向照片添加評論。 直到我從集合視圖控制器(使用removeObjectsAtIndexPaths
)或詳細信息視圖控制器(使用deleteInBackgroundWithBlock
) 刪除 UserPhoto之前,此工作流程均能完美無誤地工作。
問題的范圍很廣。 當我在執行刪除操作后嘗試對任何現有對象(不僅僅是UserPhoto)執行任何類型的保存操作時,都會得到:
"[Error]: object not found for update (Code: 101, Version: 1.11.0)"
delete
操作后恢復save
功能的唯一方法是完全退出應用程序。
我在這里死 謝謝。
源代碼
首先,一個簡單的函數用於遍歷collectionView
中所選照片的數組並調用removeObjectsAtIndexPaths
。 盡管removeObjectsAtIndexPaths
有點神秘(有限文檔),但我已經確認它會立即從Parse中刪除對象。
func deleteSelectedPhotos() {
var indexPaths = [NSIndexPath]()
for image in self.selectedImages {
let index = self.objects.indexOf({ (photo: AnyObject) -> Bool in
return image == photo as! PFObject
})
let indexPath = NSIndexPath(forItem: index!, inSection: 0)
indexPaths.append(indexPath)
}
self.removeObjectsAtIndexPaths(indexPaths)
}
這是照片詳細信息屏幕的刪除代碼:
func deleteUserPhoto() {
currentPhoto.deleteInBackgroundWithBlock { (deleted: Bool, error: NSError?) -> Void in
if let error = error {
print("error deleting photo")
print(error.localizedDescription)
} else {
if deleted == true {
self.delegate?.photoDetailVcDidDeletePhoto(self.currentPhoto)
self.navigationController?.popViewControllerAnimated(true)
}
}
}
}
底部附近的委托方法由PFQueryCollectionViewController
調用,因此它可以loadObjects
並更新UI以反映刪除。
我想我解決了這個問題。 在創建新的UserPhoto
對象時,我將它們添加到父對象(“ Album
的數組中,並保存了沒有完成塊的“ Album
。 我實際上並沒有使用數組(而是僅使用指向Album
的指針查詢UserPhoto
對象)。
當刪除代碼以將照片添加到未使用的陣列中時,我能夠再次更新並創建UserPhoto
對象。 我懷疑錯誤是指尚未完成保存的Album
對象(?)。
完全將Album
留在更新UserPhotos
的過程中似乎做到了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.