ios - Append text to a UITextField with custom keyboard made out of buttons -
i have static numeric-keyboard made out of bunch of buttons, have 3 uitextfields
, textfield1, textfield2 , textfield3 i'm inputting text using static keyboard.
here code i'm using detect textfield in focus , input content of buttons. kind of works don't fact have 3 if statements , i'm not sure how prevent keyboard appearing when textfield tapped.
what best way implement functionality?
@ibaction func appendkey(sender: anyobject) { let digit = sender.currenttitle! if(textfield1.isfirstresponder()){ textfield1.text = textfield1.text! + digit! }else if(textfield2.isfirstresponder()){ textfield2.text = textfield2.text! + digit! }else if(textfield3.isfirstresponder()){ textfield3.text = textfield3.text! + digit! } }
thanks
if standard keyboard displaying custom keyboard isn't setup properly. custom keyboard should inputview
of each uitextfield
. if that, standard keyboard won't appear , yours instead.
your custom keyboard should separate class handles of it's own buttons. appears have in 1 view controller - of text fields, of buttons, , of button handling code. bad approach. create custom keyboard class view. put of code handle , display buttons in custom view class. create single instance of view in view controller , assign custom keyboard view instance inputview
property of each text field.
in custom keyboard class, listen uitextfieldtextdidbegineditingnotification
notification. how keep track of current text field. custom keyboard class should not have specific reference text field other track current one. should ensure text field's inputview
itself.
in each button handler of custom keyboard class, text wish append , call text field's inserttext:
method string. that's it. ensure text inserted and/or replaced based on current selecting in text field.
Comments
Post a Comment