, Для этого вы должны встроить свой viewcontroller в navigationcontroller в раскадровку. Перейдите в Редактор -> Внедрить -> Контроллер навигации.

лал несколько UIButton в indexPath вUICollectionViewCell программно. теперь я хочу напечатать "нажал добавить в избранное", но после нажатия ничего не печатаетсяUIButton,UIButton просматривает все, кромеaddTarget функция не щелкает.

import UIKit

//**UICollectionViewCell**
class DescriptionCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {


    override init(frame: CGRect) {
        super.init(frame: frame)


        setupCell()

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }



    lazy var addToCart: UIButton = {

        let btn = UIButton()
        btn.setTitle("Add to favourite", for: .normal)
        btn.isUserInteractionEnabled = true
        btn.setTitleColor(.white, for: .normal)

        btn.backgroundColor = UIColor.orange
        btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 8)
        btn.titleLabel?.textAlignment = .right

        // addToCart not click
        btn.addTarget(self, action: #selector(addToCartTarget), for: .touchUpInside)

        btn.layer.cornerRadius = 12

        return btn
    }()




    func setupCell() {



        addSubview(addToCart)



        addConstraintsWithFormat("H:|-80-[v0]-80-|", views: addToCart)
             addConstraintsWithFormat("V:|-380-[v0(25)]|", views: addToCart)


    }



    func addToCartTarget() {

        print("you clicked add to favourite")
    }




}

Ответы на вопрос(1)

Ваш ответ на вопрос