How to use addTarget method in swift 3

后端 未结 10 1379
清酒与你
清酒与你 2020-11-29 02:20

here is my button object

    let loginRegisterButton:UIButton = {
    let button = UIButton(type: .system)
    button.backgroundColor = UIColor         


        
10条回答
  •  独厮守ぢ
    2020-11-29 02:41

    In swift 3 use this -

    object?.addTarget(objectWhichHasMethod, action: #selector(classWhichHasMethod.yourMethod), for: someUIControlEvents)
    

    For example(from my code) -

    self.datePicker?.addTarget(self, action:#selector(InfoTableViewCell.datePickerValueChanged), for: .valueChanged)
    

    Just give a : after method name if you want the sender as parameter.

提交回复
热议问题