我有以下代码:
var selectedIndexPaths = [NSDate]()
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as? PartExpense
if cell?.selected == true {
cell?.layer.borderWidth = 4.0
cell?.layer.borderColor = UIColor.greenColor().CGColor
selectedIndexPaths.append(cell!.idPartecipant)
print(selectedIndexPaths)
}
}
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
if cell?.selected == false {
cell?.layer.borderColor = UIColor.clearColor().CGColor
if let index = selectedIndexPaths.indexOf(indexPath.row) {
selectedIndexPaths.removeAtIndex(index)
print(selectedIndexPaths)
}
}
}
一切顺利,直到行: 如果让index = selectedIndexPaths.indexOf(indexPath.row)
这是错误:“无法将 Int 类型的值转换为预期的 NSDate 类型”我该如何实现此目的?如何转换数组以避免此错误?
最佳答案
您编写的方式是询问该数组中的所有 NSDate 日期“indexPath.row”的索引是什么。错误是说indexPath.row是一个int而不是一个日期。您到底想做什么?
关于arrays - 从 collectionView 中取消选择并从数组中取消项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36319107/