UIButton我在UICollectionViewCell中,但它不工作,當我點擊它去另一個ViewController鄙視我訪問它。我發佈我的兩個班級代碼。爲什麼它發生?不工作UIButton來自UICollectionViewCell
類DetailController:UICollectionViewController,UICollectionViewDelegateFlowLayout {
var arrDetailProduct = [Product]()
let descriptionCellid = "descriptioncellid"
let reviewAverageRateCellid = "reviewaveragerateid"
let baceCellId = "baceCellid"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.register(ReviewAverageRate.self, forCellWithReuseIdentifier: reviewAverageRateCellid)
collectionView?.register(BaseCellNew.self, forCellWithReuseIdentifier: baceCellId)
}
func showAppDetailForApp(){
let appDetailController = GiveReviewViewController()
navigationController?.pushViewController(appDetailController, animated: true)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reviewAverageRateCellid, for: indexPath) as! ReviewAverageRate
cell.detailControllr = self
return cell
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
}
類ReviewAverageRate:UICollectionViewCell {
var detailControllr = DetailController()
override init(frame: CGRect) {
super.init(frame: frame)
setupDigitalReviewAverageRate()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let giveReviewBtn: UIButton = {
let btn = UIButton()
btn.setTitle("GIVE REVIEW", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.backgroundColor = UIColor.orange
btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 10)
btn.addTarget(self, action: #selector(giveReviewBtnTarget), for: .touchUpInside)
return btn
}()
func giveReviewBtnTarget() {
detailControllr.showAppDetailForApp()
}
func setupDigitalReviewAverageRate() {
addSubview(giveReviewBtn)
addConstraintsWithFormat("H:|[v0(80)]|", views: giveReviewBtn)
addConstraintsWithFormat("V:|[v0(20)]|", views: giveReviewBtn)
}
}
你需要爲你的創建委託,然後打開showAppDetailForApp從你的DetailController。 – GeneCode
@GeneCode感謝您的回答,請嘗試更多詳細信息 –
這段代碼中會發生什麼,您可以詳細說明一下,以及您想要做什麼? – KKRocks