繁体   English   中英

子视图UIButton单击事件无法从ViewController迅速4

[英]subview UIButton click event not working from ViewController swift 4

我的自定义EmptyUIView 我想从UIViewController调用UIView uiBtnExplore。

class EmptyView: UIView {
    @IBOutlet weak var uiBtnExplore: UIButton!

    class func createEmptyView() -> EmptyView {
        let myEmptyNib = UINib(nibName: "EmptyView", bundle: nil)
        return myEmptyNib.instantiate(withOwner: nil, options: nil)[0] as! EmptyView
    }
}

我的UIViewController:

import UIKit
import XLPagerTabStrip

class PlaylistViewController: UIViewController, IndicatorInfoProvider {
    var itemInfo: IndicatorInfo = "PLAYLISTS"
    var emptyView:EmptyView!

    func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
        return itemInfo
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        emptyView = EmptyView.createEmptyView()
        self.emptyView.center = CGPoint(x: view.frame.size.width  / 2,
                                        y: view.frame.size.height / 2)
        self.view.addSubview(emptyView)
        self.view.bringSubviewToFront(testButton)
        view.isUserInteractionEnabled = false

        self.emptyView.uiBtnExplore.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
    }

    @objc func buttonAction(sender: UIButton!) {
        print("Button Clicked")
    }
}

您已禁用与视图的userInteraction,当您禁用用户交互时,它与其所有子视图的禁用交互都在行下方更改

view.isUserInteractionEnabled = false

view.isUserInteractionEnabled = true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM