ios - Button action done when touched outside of keyboard - Swift Xcode -
i using following code enter value in uitextfield
'item', on clicking button addbutton
value in textfield
appended array , clear textfield
. have added code hide keyboard when touched outside.
the problem is, after typing word in textfield
, touching outside, action in button in done, before button pressed
@iboutlet weak var item: uitextfield! @ibaction func addbutton(sender: anyobject) { todolist.append(item.text!) item.text = "" } override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) { self.view.endediting(true) }
i don't know problem, because new swift,
first delete the
@iboutlet weak var item: uitextfield! & @ibaction func addbutton(sender: anyobject) { todolist.append(item.text!) item.text = "" }
02.then go story board click view controller , click last button sign of arrow right. check outlets. delete item , add button on list.
then again add text field , add button view controller. click text field + ctrl ad connect line view controllers code, same addbutton ,use touch inside not touching outside
add these functions code , run project.
override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { self.view.endediting(true)
}
func textfieldshouldreturn(textfield: uitextfield) -> bool { textfield.resignfirstresponder() return true
}
hope these steps you. if not leave comment
Comments
Post a Comment