ios - Swift: Multiple UIButton in a IndexPath in a UICollectionViewCell programmatically, next addTarget does not click -


i made multiple uibutton in indexpath in uicollectionviewcell programmatically. want print "clicked add favourite" not printing after click uibutton. uibutton view except addtarget function not click.

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 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 favourite")     }     } 

enter image description here

try initializing button frame like:

let btn = uibutton(frame: cgrect(x: 10, y: 10, width: 50, height: 20)) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -