我的自定义 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")
}
}
最佳答案
您已禁用用户与您的 View 的交互,当您禁用用户交互时,它会禁用与其所有 subview 的交互,更改如下
view.isUserInteractionEnabled = false
与
view.isUserInteractionEnabled = true
关于ios - subview UIButton 单击事件在 ViewController swift 4 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52739590/