【发布时间】:2016-02-09 19:13:00
【问题描述】:
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()
}
}
我可以一次删除两张照片。当我选择三张照片时,它会给出绑定错误的数组索引。我现在没主意了!!
【问题讨论】:
-
发布你的代码并描述更多
标签: ios iphone arrays swift core-data