【发布时间】:2015-12-28 00:51:04
【问题描述】:
我已经使用this tutorial 成功地将UICollectionView 嵌入到我的ViewController 中的UITableView 中。
如果您快速查看链接教程的代码,以下内容可能会更有意义(加上它也是一个非常值得学习的东西!):
对我来说,下一步是从 tableView 的 UITableViewCells 内的 UICollectionView 的单元格执行 segues,但由于 collectionView 出口是在单独的视图控制器中建立的,我不知道如何引用它在主 ViewController 中。
在 TableViewCell.swift 中有:
class TableViewCell: UITableViewCell {
@IBOutlet private weak var collectionView: UICollectionView!
}
extension TableViewCell {
func setCollectionViewDataSourceDelegate<D: protocol<UICollectionViewDataSource, UICollectionViewDelegate>>(dataSourceDelegate: D, forRow row: Int) {
collectionView.delegate = dataSourceDelegate
collectionView.dataSource = dataSourceDelegate
collectionView.tag = row
collectionView.reloadData()
}
}
例如,在 ViewController.swift 中,我需要能够在 ViewController.swift 文件中的 prepareForSegue 函数中调用 TableViewCell 中的 collectionView。我只需要用 collectionView 插座来填补空白:
let destination = segue.destinationViewController as! SecondViewController
let indexPaths = self.___________.indexPathsForSelectedItems()
let indexPath = indexPaths![0] as NSIndexPath
let arrayObject = self.arrayObjects[indexPath.row]
destination.object = arrayObject
'object' 在 SecondViewController 中实现,就像这样,var object: PFObject!。
我现在需要用 collectionView 填补上述代码中的空白,________,以便在 SecondViewController(destinationViewController)中显示正确的“对象”
【问题讨论】:
标签: swift uitableview uicollectionview segue