I currently have a button (IBAction) that I'm planning on adding an IAP feature to so the user can purchase extra lives when they're about to run out, but before I get ahead of myself I'd like to figure out how to only show this button when lives == 1 and no other time.
After hours of research and failed attempts my conclusion is that yes, you can hide a button (UIButton) with buttonName.hidden = Bool, and switch it on/off quite easily using conditional statements.
Error: (UIButton) ->() does not have a member named hidden.
But, you can't do this quite as easily (or to my knowledge, at all) using .hidden. I can clearly see the "Hidden" checkbox in the Attributes inspector for the button and if I manually check it, it will at least remain hidden when running the app, but no idea how I can invoke this with conditional code.
Any help would be appreciated!
You are confusing actions (IBAction
) with outlets (IBOutlet
). An action is the code that your button runs when it is tapped. An outlet is what gives you access from your code to your button. You need an outlet. Make an outlet from your view controller to your button. Let's call it myButton
. Then in viewWillAppear:
decide whether self.myButton
should be shown or hidden, and set its hidden
accordingly.