【问题标题】:UIButton doesn't work when the searchController is active?当 searchController 处于活动状态时,UIButton 不起作用?
【发布时间】:2020-10-26 14:54:18
【问题描述】:

我正在使用带有搜索控制器的UICollectionViewCompositionalLayout

just like this

问题:

当搜索控制器处于活动状态时,我无法点击部分标题中的 UI 按钮。但是该部分的 GestureRecognizer 工作正常。

当我不搜索任何内容时,它们都可以工作,如果在搜索时点击键盘上的“输入”,按钮就会开始工作。

我做错了什么?

【问题讨论】:

    标签: ios swift uisearchbar uicollectionviewcompositionallayout


    【解决方案1】:

    我刚刚找到了解决方案。对于有问题的人: 我是这样添加目标的

    let button: UIButton = {
            let button = UIButton(type: .custom)
            button.setTitle("See all", for: .normal)
            button.setImage(UIImage(systemName: "chevron.right", withConfiguration: buttonConfig), for: .normal)
            
            button.addTarget(self, action: #selector(myFunc), for: .touchUpInside)
            
            return button
        }()
    

    删除 addTarget,并将其添加到类的 Init 中可以解决问题。

    override init(frame: CGRect) {
        super.init(frame: frame)
    
        addSubview(button.addTarget)
        button.addTarget(self, action: #selector(myFunc), for: .touchUpInside)
    }
    

    我不知道为什么,但它有效。哈哈

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 2016-04-06
      相关资源
      最近更新 更多