enter image description here我想刪除其通過用戶
func OnDelPressed(){
let selectedItem = self.collection.indexPathsForSelectedItems()
print(selectedItem?.count)
deleteItemsAtIndexPaths(selectedItem!)
}
func deleteItemsAtIndexPaths(indexPaths: [NSIndexPath]){
for indexpath in indexPaths{
//print(photos[indexpath.item])
print("index number is: \(indexpath.row)")
print(photos[indexpath.row])
print("number of photos are :\(photos.count)")
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext
let photo = photos[indexpath.row] as NSManagedObject
context.deleteObject(photo)
do{
photos.removeAtIndex(indexpath.item)
try context.save()
}catch{
let saveError = error as NSError
print(saveError)
}
collection.reloadData()
}
}
選擇我可以刪除兩張照片在單個時間。當時我選擇三個相片它給界錯誤的數組索引多張照片。我現在沒有想法!
發佈您的代碼並添加說明 – jbcd13