【发布时间】:2021-09-26 14:24:42
【问题描述】:
我已经创建了 xib 集合视图单元.. 我可以在 HomeVC 中使用它的所有值,如下所示
class HomeVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
@IBOutlet var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "MainCollectionViewCell", bundle: nil)
collectionView.registerNib(nib, forCellWithReuseIdentifier: "MainCollectionViewCell")
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MainCollectionViewCell", forIndexPath: indexPath) as! MainCollectionViewCell
cell.arrivingLabel.text = indexData.arriv
cell.lblDiscountedPrice.text = indexData.discPrice
return cell
}
如下所示,我可以对 xib 单元格按钮进行操作,但我想要 HomeVC 类中的 xib 单元格按钮操作如何,请在此处指导我
cell.btnDetails.addTarget(self, action: #selector(connected(sender:)), for: .touchUpInside)
@objc func connected(sender: UIButton){
}
我想在 HomeVC 中这样
@IBAction func productDetailsMain(_ sender: UIButton){
}
注意:如果我使用相同的 collectionview 单元格,那么如果我从 HomeVC 按钮操作出口拖动到 collectionview 单元格按钮,那么它的添加.. 但如果我在 collectionview 中使用 xib 单元格,则此过程不起作用.. 如何在 HomeVC 类中赋予 xib 单元格按钮操作
【问题讨论】:
标签: swift button action cell xib