gpt4 book ai didi

ios - 按钮操作不适用于 subview

转载 作者:行者123 更新时间:2023-11-28 10:53:25 24 4
gpt4 key购买 nike

在我的一个 iOS 项目中,我以编程方式在我的 Feed ViewController(主视图)上添加了 Filter ViewController( subview )的 subview 。

Filter ViewController 上有几个按钮可以选择价格、城市等。

socket 已连接,但当我尝试拍摄按钮 Action 时,它不起作用。我还启用了 isUserInteractionEnabled,但它仍然无法正常工作。

累积。对我来说,这是与 View 上的 subview 相关的东西!但要解决这个问题。你能建议我如何拍摄 subview 的按钮 Action 吗?

class FilterViewController: BaseUIViewController{

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

cityButton.isUserInteractionEnabled = true
}

@IBAction func selectCity(_ sender: Any)
{
print("selectCity action")
}
}

最佳答案

使用下面的代码将您的 FilterViewController 作为 subview 添加到您的 ViewController

filterViewController.willMove(toParentViewController: self)
self.view.addSubview(filterViewController.view)
self.addChildViewController(filterViewController)
filterViewController.didMove(toParentViewController: self)

关于ios - 按钮操作不适用于 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45012561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com