Matt Jacquet Matt Jacquet - 7 months ago 46
Swift Question

nsuserdefaults in viewdidload disable hidding views

I'm using nsuserdefaults to save some bools data but I'm facing problem:
in my storyboard, I checked 'hidden' for a view, but when I use my application, the view is not 'hidden' and i noticed it's because my userdefaults in the

when i delete it, the view is hidden.
Is there a way to set it hidden?
i tried in
to set hidden but don't work.
here's my code:

override func viewDidLoad() {
// viewnote2.hidden = true
let boolsKey = NSUserDefaults.standardUserDefaults()
viewnote2.hidden = boolsKey.boolForKey("bool2")

that's all about this view


Some time change on UI doesn't work on viewDidLoad, try to hide the view on viewDidAppear. Also check that you have set the Bool value for bool2 key in UserDefaults.

If you haven't set the Bool value in UserDefaults than you need to set first like this.

let boolsKey = NSUserDefaults.standardUserDefaults()