Reputation: 3
I am using Xcode 8. In my code, I have certain items hidden, but when I launch the simulator to test, those same items show up. Is there something that I am missing?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var logoImg: UIImageView!
@IBOutlet weak var howManyTapsTxt: UITextField!
@IBOutlet weak var playBtn: UIButton!
@IBOutlet weak var tapBtn: UIButton!
@IBOutlet weak var tapsLbl: UILabel!
@IBAction func onPlayBtnPressed (sender: UIButton!) {
logoImg.isHidden = true
playBtn.isHidden = true
howManyTapsTxt.isHidden = true
tapBtn.isHidden = false
tapsLbl.isHidden = false
}
}
My code is above. The logo, howManyTapsTxt, and playBtn should be the only items shown when the simulator is launched. And when the playBtn is pressed, the tapsLbl and tapBtn should be the only items shown. But that is not the case. Any help/guidance is greatly appreciated. Thanks.
Upvotes: 0
Views: 55
Reputation: 318774
Your posted code makes no attempt to set the initial state of any of your views. The typical solution is to set the state in the viewDidLoad
method.
override func viewDidLoad() {
super.viewDidLoad()
// Set the initial state of your views here
tapBtn.isHidden = true
tapsLbl.isHidden = true
}
The other option is to mark these views as hidden in Interface Builder.
Upvotes: 1