r_s*_*rma 0 filtering button subview ios swift
在我的一个 iOS 项目中,我以编程方式在我的 Feed ViewController(主视图)上添加了 Filter ViewController(子视图)的子视图。
Filter ViewController 上有几个按钮可以选择价格、城市等。
插座已连接,但当我尝试拍摄按钮动作时,它不起作用。我还启用了 isUserInteractionEnabled 但它仍然不起作用。
附件。对我来说,这与视图上的子视图有关!但要解决这个问题。你能建议我如何拍摄子视图发生的按钮动作吗?
class FilterViewController: BaseUIViewController{
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
cityButton.isUserInteractionEnabled = true
}
@IBAction func selectCity(_ sender: Any)
{
print("selectCity action")
}
}
Run Code Online (Sandbox Code Playgroud)
使用下面的代码将 FilterViewController 作为子视图添加到 ViewController
filterViewController.willMove(toParentViewController: self)
self.view.addSubview(filterViewController.view)
self.addChildViewController(filterViewController)
filterViewController.didMove(toParentViewController: self)
Run Code Online (Sandbox Code Playgroud)