func backBtnAction(){
var index = collectionView?.indexPathsForSelectedItems() as! [NSIndexPath]
collectionView?.scrollEnabled = true
collectionView?.reloadItemsAtIndexPaths(index)
}
如何在indexpath
中获取collectionview
...就像我正在做的那样
var index = collectionView?.indexPathsForSelectedItems() as! [NSIndexPath]
答案 0 :(得分:1)
indexPathsForSelectedItems()
返回[NSIndexPath]?
,所以通常的方式是可选绑定而不需要强制转换
func backBtnAction()
{
if let indexes = collectionView?.indexPathsForSelectedItems() {
collectionView!.scrollEnabled = true
collectionView!.reloadItemsAtIndexPaths(indexes)
}
}