Swift/UISwitch: how to implement a delegate/listener

后端 未结 7 1729
慢半拍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 Swift4.0

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

提交回复
热议问题