Swift/UISwitch: how to implement a delegate/listener

后端 未结 7 1695
慢半拍i
慢半拍i 2020-12-29 19:24

In my UITableViewController I have a custom cell which contains a switcher which is the following:

import Foundation
import UIKit

class SwitchCell: UITableV         


        
7条回答
  •  既然无缘
    2020-12-29 19:56

    In Swift 5

    switchDemo.addTarget(self, action: #selector(didTapAdvertise), for:UIControl.Event.valueChanged)
    
    @objc func didTapAdvertise(mySwitch: UISwitch) {
            let value = mySwitch.isOn
            // Do something
            print("switch value changed \(value)")
        }
    

提交回复
热议问题