【发布时间】:2018-04-04 13:14:53
【问题描述】:
我正在使用 Swift3 和 Xcode 8.3.3
我正在研究包含 UICollectionView 的 UITableViewCell。
每个 CollectionView 单元都需要执行 segue。
我的意思是,我需要用导航控制器调用其他 ViewController。所以用户可以回到主 UITableViewController。
import UIKit
class PastCell: UITableViewCell {
@IBOutlet weak var ptripDtls: UICollectionView!
var logcount:Int = 0
override func awakeFromNib() {
super.awakeFromNib()
ptripDtls.delegate = self
ptripDtls.dataSource = self
logcount = Transfer.tripObj[Transfer.cellpos]["logcount"]! as! Int
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let width = self.ptripDtls.collectionViewLayout.collectionViewContentSize.width;
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
layout.itemSize = CGSize(width: width-17 , height: 50)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 1
ptripDtls!.collectionViewLayout = layout
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
extension PastCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return logcount
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PastTripCollectionCell", for: indexPath) as! PastTripCollectionCell
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//Might be here segue function will call
}
}
【问题讨论】:
-
所以你想在选择集合视图单元格时调用另一个视图控制器
-
你有什么问题?
-
让 vc = self.storyboard!.instantiateViewController(withIdentifier: Constant.vc.DestinationVC) as! DestinationVC self.show(vc, sender: self) 在你的 didselect 中写下这两行代码
-
@GoribDeveloper 这是包含集合的自定义单元格。所以我不能使用你的功能。
-
@V_rohit 是的,使用导航,所以我可以回来
标签: ios swift uitableview uicollectionview segue