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!
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

Matthew Muscat
Courses Plus Student 1,757 PointsHow can I hide a button when another button is pressed on a navigation bar?
The title says it all Thanks
2 Answers

Daniel Sattler
4,867 PointsNo problem.
You would have to add an IBOutlet AND an IBAction for all affected buttons.
assuming you have 3 buttons, Button One, Button Two and a button to reset everything, so to show all buttons again.
This is how your code would look like:
@IBOutlet weak var buttonOne: UIButton!
@IBOutlet weak var buttonTwo: UIButton!
@IBAction func buttonOnePressed() {
// When buttonOne is pressed, it hides buttonTwo.
buttonTwo.hidden = true
}
@IBAction func buttonTwoPressed() {
// When buttonTwo is pressed, it hides buttonOne.
buttonOne.hidden = true
}
@IBAction func unhideButtons() {
// when unhideButtons is pressed, it unhides all buttons
buttonOne.hidden = false
buttonTwo.hidden = false
}
I hope this leads you in the right direction ;-)

Daniel Sattler
4,867 Pointsi give you a hint:
buttonOne.hidden = true // hides buttonOne
buttonTwo.hidden = false // shows buttonTwo
I hope this leads you in the right direction ;-)

Matthew Muscat
Courses Plus Student 1,757 PointsHaha im really new to programming, can u please show me the whole block of code haha, cheers
Matthew Muscat
Courses Plus Student 1,757 PointsMatthew Muscat
Courses Plus Student 1,757 PointsHehehe yeah haha thanks!