【发布时间】:2017-06-24 16:06:36
【问题描述】:
我在从 collectionView 中以编程方式(没有情节提要)显示 viewController 时遇到了一些问题。我认为这很容易,但我很难弄清楚这一点,因为我对 swift 有点陌生。我相信 collectionViewCells 默认不是委托,所以我尝试在 collectionView 类中实现 didSelectItemAt 但仍然没有运气。在单元格的水龙头上,我收到了一份打印声明,只是没有任何表演节目。请参阅下面的 collectionViewCell 代码,提前致谢!
// collectionViewCell class
class PlanningCell: BaseCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.dataSource = self
cv.delegate = self
return cv
}()
//collectionViewCell variables
var plannedPlaces = [CurrentPlanner]()
let cellId = "cellId"
var basePlanningCell: BasePlanningCell!
override func setupViews() {
super.setupViews()
addSubview(collectionView)
collectionView.register(BasePlanningCell.self, forCellWithReuseIdentifier: cellId)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return plannedPlaces.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! BasePlanningCell
cell.currentPlanner = plannedPlaces[indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("did tap")
let plannersDetailVC = PlanningPlaceDetailsVC()
plannersDetailVC.navigationTitle = plannedPlaces[(indexPath.row)].planningPlace
// below I am receiving the use of unresolved identifier "show" error
show(plannersDetailVC, sender: self)
}
}
【问题讨论】:
标签: swift delegates uicollectionview segue uicollectionviewcell