2016-11-10 57 views
-2

我正在使用Swift 3为选定项目获取indexPath。代码看起来像这样。indexPathsForSelectedItems不会在Swift 3上返回IndexPath

override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
{ 
    let indexPaths = collectionView.indexPathsForSelectedItems! 
    print(indexPaths) 
} 

但是这一次打印出空数组如[]而不是集合视图细胞的选定的项目的阵列。我如何获得所选单元格的indexPath行?

+0

您是否取消选择所选代表功能中的项目? – Tj3n

+0

你需要显示你的'didSelectItemAt indexPath'方法。 –

+0

我选择了委托功能。但它仍然返回零数组。 – fzlrhmn

回答

0

我知道我的代码有什么问题。我已经使用didDeselectItemAt而不是didSelectItemAt。案件结案。谢谢大家。