user6428350
user6428350

Reputation:

How do i hide a button through the user pressing a button

My app is a quiz app and what i am trying to do is when the user selects an incorrect answer it will either stop running the quiz app and show a button for the user to go to the beginning. Or it will hide all the buttons and labels except the button to go back to the beginning. Which ever one is easier.

please let me know! I have tried things like Button1.hidden = true/YES but it doesn't hide the button

Thanks

@IBAction func Button1Action(sender: AnyObject) {

    if AnswerNumber == 0 {
        PickQuestion()
        LabelEnd.text = "Goodjob buddy"
    }    
    else {
        Hide()
        LabelEnd.text = "Unlucky pal"
        Again.hidden = false
        QuestionLabel.hidden = true 
    }
}

Upvotes: 0

Views: 60

Answers (2)

Mahendra
Mahendra

Reputation: 8924

You can do like....

There will be rootViewController from where user start quiz.

So when user select incorrect answer then you can redirect user to rootViewController by calling popToRootViewController: method.

And you can also show an alert.

So you don't need to hide or show any thing.:)

Upvotes: 0

user6514354
user6514354

Reputation:

UILabel , UIButton are inherited from UIView. And UIView has a property 'isHidden'. So, If you do

someview.isHidden = true

this will work as a function and hide the view from layout! Try again!

Upvotes: 2

Related Questions