iphone - UITextField strange behavior when delete symbol in first time -


when push viewcontroller 1 of textfield must have text, make , good

 cell.textfieldmain.text = [nsstring stringwithformat:@"+7 (%@) %@-%@",[num substringtoindex:3], [num substringwithrange:nsmakerange(3, 3)], [num substringfromindex:6]]; 

i have method put cursor in needed place, because make template textfield

my method:

- (void)setcurcorfortextfield:(uitextfield *)textfield position:(nsinteger)position { uitextposition *newposition = [textfield positionfromposition:textfield.beginningofdocument offset:position]; uitextrange *newrange = [textfield textrangefromposition:newposition toposition:newposition]; [textfield setselectedtextrange:newrange]; } 

in method changing have

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {  //other conditions  else {         textfield.text = [nsstring stringwithformat:@"+7 (%@) %@-%@",[num substringtoindex:3], [num substringwithrange:nsmakerange(3, 3)], [num substringfromindex:6]];         if (length == 7)             [self setcurcorfortextfield:textfield position:14];         else if (length == 8)             [self setcurcorfortextfield:textfield position:15];         else if (length == 9)             [self setcurcorfortextfield:textfield position:16];         else if (range.length)             [self setcurcorfortextfield:textfield position:17];     } } return yes; 

so when first try delete last character take empty field, must have +7 (123) 456-789 (phone number 10 numbers without last deleted. in other cases work fine. , when push thid viewcontroller in next time, , tableview textfield created again have no trouble , work fine.

when push mu viewcontroller see enter image description here

i try delete last character , empty field appear

enter image description here

but in other cases when push viewcontroller again work fine , can delete last cahracter

enter image description here

when delete characters , type new number , , editing, after begining editing field , try delete - work fine. work fine^ first time work bad


Comments