@IBAction func buttons in stack view do not work

When I put a button linked to an @IBAction into a stack view the function does not work. Is this a bug or feature?

I am using Swift 5 on an IOS app. Xcode 10.2.1 Mohave 10.14.6 Beta

Accepted Reply

It should not have to do with the variations for traits.


Can you show the exact code for the IBAction ?

And to which button event it is connected to ?


I tested with 2 buttons, first out of any stackView.


Connected them to the 2 IBActions

    @IBAction func buttonAction1(_ sender: UIButton) {
        print(sender.currentTitle!)
    }
   
    @IBAction func buttonAction2(_ sender: UIButton) {
        print(sender.currentTitle!)
    }


It works.


Then embedded in stackView (Editor menu)


Still works.

Replies

I tested on 10.14.5 Mojave. It works well.


You say it doesn't work, what do you get exactly ?


When you look at buttons connections, are they connected to the IBAction for touch up inside event ?

The button is connected and works if moved outside of the stack view. This may be somehow related to my use of Vary by Traits as I have to get these views to work on multiple devices. In the meantime I am going to keep the action buttons out of Stacks.


Thanks for taking a look at this.

It should not have to do with the variations for traits.


Can you show the exact code for the IBAction ?

And to which button event it is connected to ?


I tested with 2 buttons, first out of any stackView.


Connected them to the 2 IBActions

    @IBAction func buttonAction1(_ sender: UIButton) {
        print(sender.currentTitle!)
    }
   
    @IBAction func buttonAction2(_ sender: UIButton) {
        print(sender.currentTitle!)
    }


It works.


Then embedded in stackView (Editor menu)


Still works.

I think the problem was that I created the stack view while Vary for Traits was active (for iPhone8) then drug the button into the stack view and then tried to run the app on an iPad. The view showed the stack view but the buttons in it were not active. When I moved the button out of the stack it became active, and the labels that were set by the buttons action (still in the stack view) did show the correct results.


Here is the button's action



@IBAction func startWhenInUse(_ sender: Any) {

print (CLAuthorizationStatus.self)

locationManager.requestWhenInUseAuthorization()

print (CLAuthorizationStatus.self)

locationManager.startUpdatingLocation()


}