ios - First tap to the second UITextfield located inside tableviewcell didn't start editing (display cursor). Only the second tap works. Why? -


i have tableviewcell , 3 textfields inside. click fist 1 (is called "target") , input number. keyboard displayed dismissed tapping done button on keyboard (resignfirstresponder() attached done button).

when try edit second textfield (is called "actual") without keyboard dismissal cursor doesn't appear on first tap textfield means editing didn't start (image 1 below). need tap textfield second time cursor appear (image 2 below).

how can make cursor appear first tap second editing textfield?

and not want hide keyboard (launch resignfirstresponder()) when user decides continue input let 4-5 fields in row. editing in textfield should end , start when user taps textfield. edits whatever textfields needs , hits done on keyboard @ end.

(in fact cursor in second textfield appears first tap if user tapped first textfield inputted nothing)

my code:

i highlight / dishighlight border of editing textfield:

func textfieldshouldbeginediting(textfield: uitextfield) -> bool // highlight textfield when editing {     textfield.layer.borderwidth = 1     textfield.layer.cornerradius = 2     textfield.layer.bordercolor = uicolor.bluecolor().cgcolor     return true }    func textfieldshouldendediting(textfield: uitextfield) -> bool  // hide  highlight textfield when editing {      textfield.layer.borderwidth = 1     textfield.layer.bordercolor = uicolor.clearcolor().cgcolor      return true } 

i assign text before input variable check later prevent data processing if user didn’t change text:

func textfielddidbeginediting(textfield: uitextfield) // remember number before user input prevent actions when no input {     textineditfield = textfield.text! }  func textfielddidendediting(textfield: uitextfield) {     if  textfield.text == textineditfield // no actions if field empty or text not changed     {           return     }    … inputed text processing }  

what tried:

  1. tourchesbegan. read used plain view , doesn’t work scrollview case tableview

    override func touchesbegan(touches: set<uitouch>, withevent event: uievent?)     {         self.view.endediting(true)     } 
  2. to put textfield.resignfirstresponder() textfielddidendediting(). know don’t want keyboard dismissed when user edit second textfield tried check if works.

  3. there solution how dismiss keyboard on touch tableview background. not need keyboard dismissed cause user continue editing textfields. dismiss keyboard touching background of uitableview

[the first tap on second textfield doesn't show cursor][2] [2]: http://i.stack.imgur.com/a4voz.png [the second tap on second textfield shows cursor][3] [3]: http://i.stack.imgur.com/l82a5.png

i figured out solution.

in textfielddidendediting() function had tableview.reloaddata(). sequence of operations following:

  1. a user touches textfield1 , editing. following functions fired behind curtain textfield1: textfieldshouldbeginediting() > textfielddidbeginediting()
  2. a user touches textfield2. following functions fired behind curtain:

    for textfield1: textfieldshouldendediting() > textfielddidendediting() > tableview.reloaddata()

    for textfield2: textfieldshouldbeginediting()

the fact tableview.reloaddata() run in textfielddidendediting() of textfield1 reason why textfielddidbeginediting() of textfield2 not fired , editing session has not been started. tableview.reloaddata() launches resignfirstresponder().

to overcome behavior need make textfield2 becomefirstresponder before tableview.reloaddata() , after. here code

    textfield2.becomefirstresponder()     tableview.reloaddata()      let delayinseconds = 0.1      let poptime : dispatch_time_t = dispatch_time(dispatch_time_now, int64(delayinseconds * double(nsec_per_sec)))     dispatch_after(poptime, dispatch_get_main_queue(),         {             nexttextfield.becomefirstresponder()         }) 

here answer helped me https://stackoverflow.com/a/16462473/5826451


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -