【发布时间】:2016-03-30 20:29:57
【问题描述】:
我有以下代码:
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)
}
}
}
一切顺利,直到行: if let index = selectedIndexPaths.indexOf(indexPath.row)
这是错误:“无法将 Int 类型的值转换为预期的 NSDate 类型”我该怎么做才能做到这一点?如何转换数组以避免此错误?
【问题讨论】:
标签: arrays swift uicollectionview