Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Swift ibaction func only triggered once even though button is tapped several times

Hi, so i am making a project in the swift techdegree. I have made an ibaction func (_ sender: UIButton)

i have 3 different buttons attached to this function. when the first button is tapped once it triggers the function correctly. But if i tap it again nothing happens.

IBaction func moveUp(_ sender: UIButton) {
var placement = [string1, string2, string3, string4]
swap(&placement[1], &placement[0] )
}

How do i get the function to trigger every time the button is tapped?

thanks! :)

1 Answer

Hey Daniel,

Is this copied right from your code in your project? If so, not sure how any of the buttons work, as you have IBaction, when it should be @IBAction. If you just typed this out and it wasn’t copied directly from your project, you may have dragged from constraints instead of the buttons from your storyboard to your controller file. Check the Connections Inspector while in your Main.storyboard file. It’s up near the top right-hand side of Xcode and looks like a circle with an arrow pointing to the right. Look at this while you have your button(s) selected in the Document Outline to make sure everything is connected right. If none of that works, not sure what it could be though.