UIButton action not called in UIHostingController

I have added a button in UIController:

    let button = UIButton(type: .custom)
    button.setTitle("test", for: .normal)
   button.addTarget(self, action: #selector(addToSiri), for: .touchUpInside)
    self.view.addSubview(button)

Then using it in SwiftUI

    HStack {
    Controller()
    }.frame(maxWidth:.infinity, idealHeight: 60)

And then using swiftUI in UIHostingController:

let vc = UIHostingController(rootView: SwiftUIView())

But when I tap the button, the addToSiri is never called.

I don't know why.

Please show complete, executable code so that one can test.

We don't even know how SwiftUIView is defined.

Just a guess without more code.

Add addChild

        addChild(vc)  // <<-- ADD THIS
        self.view.addSubview(button)

@Claude31 Sorry for the late. I just found the reason. I had add a tapGesture by accident in swiftUI like

HStack {
    Controller()
    }.frame(maxWidth:.infinity, idealHeight: 60)
     .onTapGesture {
                    
                }

and I missed it.

The UISwitch works fine but button tap action if rejected.

UIButton action not called in UIHostingController
 
 
Q