我已经创建了 xib collectionview 单元..并且我能够在 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 单元格按钮执行操作,但我想要 xib 单元格按钮操作HomeVC
class怎么办,请在这里指导我
cell.btnDetails.addTarget(self, action: #selector(connected(sender:)), for: .touchUpInside)
@objc func connected(sender: UIButton){
}
我想在 HomeVC 中这样
@IBAction func productDetailsMain(_ sender: UIButton){
}
note:如果我使用相同的collectionview单元格,那么如果我从HomeVC按钮操作出口拖动到collectionview单元格按钮,然后添加它..但是如果我在collectionview中使用xib单元格,那么这个过程不起作用..如何在HomeVC中提供xib单元格按钮操作班级