2
    class MyClass {

    let customView: MyView

    init() {
        customView = MyView()
        customView.checkBox.addTarget(self, action: #selector(checkBoxValueChanged(_:)), for: .valueChanged)
    }

    @objc func checkBoxValueChanged(_ sender: M13Checkbox!) {
        print("checkBoxValueChanged")
    }

}

@IBDesignable class MyView: UIView {

    @IBOutlet var view: UIView!
    @IBOutlet var checkBox: M13Checkbox!

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

        setupView()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        setupView()
    }

    func setupView() {
        let bundle = Bundle(for: type(of: self))
        UINib(nibName: Constant.xib.MY_XIB, bundle: bundle).instantiate(withOwner: self, options: nil)

        view.frame = bounds
        view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
        addSubview(view)
    }
}

我想在 MyClass 中管理一个事件,但没有调用选择器。如果我在 UIViewController 中执行相同的逻辑,它会起作用,但在这种情况下不会。谁能帮我?谢谢

4

0 回答 0