【发布时间】:2015-01-06 02:47:48
【问题描述】:
我正在尝试从我的 prepareForSegue 函数中的 collectionView 访问 indexPath.row 变量。我有以下代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let selectedIndex = collectionView.indexPathsForSelectedItems() as NSIndexPath
//let myIndexPath = self.collectionView.indexPathForCell(cell: LocalFeedCollectionViewCell.self)
if (segue.identifier == "toFullImage")
{
var fullImageVC: FullImageViewController = segue.destinationViewController as FullImageViewController
fullImageVC.imageTitle = self.imageTitles[selectedIndex.row]
}
}
我收到以下 selectedIndex 错误 - “(UICollectionView, numberOfItemsInSection: Int) -> Int”没有名为“indexPathsForSelectedItems”的成员。在 Objective-C 中,我看到以下解决方案
NSIndexPath *indexPath = [self.collectionView indexPathForCell:sender];
但我不确定如何快速实现它/是否可行。
谢谢
【问题讨论】:
-
我想我可能已经通过将变量设为变量“var rowPath: Int = 0”然后将其设置为等于 indexPath.row 来解决问题。然后我可以写“fullImageVC.imageTitle = self.imageTitles[rowPath]”
-
您在问题中遇到的错误实际上是在那段代码中生成的吗?在您提供的代码中,我没有看到对
numberOfItemsInSection的任何引用。 -
是的,错误是在“let selectedIndex”行中发现的
标签: ios swift uicollectionview nsindexpath