ios - How to hide button after click -
i create start_button
, make @iboutlet
, @ibaction
@iboutlet weak var start_button: uibutton! @ibaction func start_button(sender: anyobject)
now, want hide button after click. try this, don't work:
@ibaction func start_button(sender: anyobject) { start_button.hidden = true; }
error message:
fatal error: unexpectedly found nil while unwrapping optional value (lldb)
how can hide button?
thanks helping!
its nil because haven't connected storyboard/nib. need connect outlet, can't create outlet in code , expect connected visible element. same goes action. @iboutlet
/ @ibaction
stands interface builder outlet/action
, means have connect them in interface builder
.
also better if action uses sender, , not local variable (when pointing same thing). , shouldnt use ;
at end of line.
@ibaction func start_button(sender: uibutton) // change uibutton { sender.hidden = true // or // (sender as! uibutton).hidden = true }
Comments
Post a Comment