【发布时间】:2019-01-21 05:42:05
【问题描述】:
我在UICollectionViewCell 里面有UIButton,它在UITableViewCell 里面,我需要在点击UIButton 时导航另一个UIViewController。但是UINavigationController 在UICollectionViewCell 中不起作用。有人可以帮忙吗?
我的代码中没有找到任何导航控制器。
import UIKit
class TrendingProductTVCell: UITableViewCell {
@IBOutlet weak var trendingProductCV: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
trendingProductCV.delegate = self
trendingProductCV.dataSource = self
}
}
extension TrendingProductTVCell: UICollectionViewDataSource, UICollectionViewDelegate {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = trendingProductCV.dequeueReusableCell(withReuseIdentifier: "TrendingProductsCVCell", for: indexPath) as? TrendingProductsCVCell
cell?.trendingAddToCartBtn.addTarget(self, action: #selector(addToCartBtnTapped), for: .touchUpInside)
return cell!
}
@objc
func addToCartBtnTapped(sender: UIButton){
let productDetail = trendingProductsDataArray[sender.tag]
}
}
【问题讨论】:
-
你可以在storyboard中添加导航控制器,然后你可以参考self.navigationcontroller push。此外,您应该在视图控制器类上扩展数据源方法。
标签: ios swift uitableview uicollectionview