我正在学习新的Swift编程语言,我想知道如何将数据从CollectionViewController传递到TableViewController。Swift - 将数据从CollectionView传递到TableViewController
我的目标是每次有人点击CollectionViewController中的一个单元格时,此操作会将它们带到TableViewController,其中出现与所选单元格相关的图像列表。
CollectionViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "listSegue") {
if let indexPath = self.menuCollection.indexPathsForSelectedItems() {
let control = (segue.destinationViewController) as TableViewCell
control.cellImage.image = UIImage(named: sectionImages[indexPath])
}
TableViewCell.swift
class TableViewCell: UITableViewCell {
@IBOutlet weak var cellImage: UIImageView!
}
TableViewController.swift
我一定要在这里把一些代码?
请帮助我,我真的很感激它:)谢谢:)
哦,我明白了:)你知道我怎么能从UITableViewCell访问我的cellImage变量?我想在我的CollectionViewController中访问这个变量 – ketokun 2014-11-05 23:18:30
你不能 - 它看起来像你的'TableViewCall'类,因此这就是你必须放在你的'UICollectionView'中 - 这是一个教程(尽管在Objective C):http://skeuo.com/uicollectionview-custom-layout-tutorial – 2014-11-05 23:26:56