【发布时间】:2016-09-27 15:11:01
【问题描述】:
我是 Swift 新手。我正在尝试在详细视图中显示图像,该图像来自UICollectionViewController。我的问题是:
- 如何通过 segue 将数据发送到详细视图?我无法使用
if let indexPath = collectionView.indexPathForSelectedRow...那么正确的方法是什么? - 如何判断用户何时点击来自
UICollectionViewController不同部分的图像,然后将此信息传递给DetailView?
AudiUICollectionViewController.swift:
import UIKit
class AudiUICollectionViewController: UICollectionViewController {
var audiPictures01:[carData] = [
carData(name:"01", picture:"1"),
carData(name:"02", picture:"2"),
carData(name:"03", picture:"3"),
carData(name:"04", picture:"4"),
carData(name:"05", picture:"5"),
carData(name:"06", picture:"6")]
var audiPictures02:[carData] = [
carData(name:"07", picture:"7"),
carData(name:"08", picture:"8"),
carData(name:"09", picture:"9"),
carData(name:"10", picture:"10"),
carData(name:"11", picture:"11"),
carData(name:"12", picture:"12")
]
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 2
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return audiPictures01.count
} else {
return audiPictures02.count
}
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if indexPath.section == 0 {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! AudiUICollectionViewCell
cell.collectionPicture.image = UIImage(named: audiPictures01[indexPath.row].picture)
return cell
} else {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! AudiUICollectionViewCell
cell.collectionPicture.image = UIImage(named: audiPictures02[indexPath.row].picture)
return cell
}
}
//I don't know how to set the segue to pass the data
}
AudiDetailViewController.swift:
import UIKit
class audiDetailViewController: UIViewController {
@IBOutlet weak var audiDetailImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
【问题讨论】:
-
您好 Eric,感谢您帮助纠正我糟糕的英语。
标签: swift uicollectionview segue