ios - I cannot intercept the back button of Numpad -


i want firstresponder go previous textfield when or return key pressed. textfieldshouldreturn not launched. many guys!

tried this doesn't seem work.

myviewcontroller.h

@interface myviewcontroller : uiviewcontroller <uitextfielddelegate>  @property (strong, nonatomic) iboutlet uitextfield *firstcodefield; 

myviewcontroller.m

@synthesize firstcodefield;  - (void)viewdidload { [super viewdidload]; firstcodefield.delegate = self; secondcodefield.delegate = self; thirdcodefield.delegate = self; fourthcodefield.delegate = self; fifthcodefield.delegate = self; }  - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {     nsuinteger newlength = [textfield.text length] + [string length] - range.length;      if (string.length == 0 && textfield.text.length)     {         if(textfield==fifthcodefield) {             nslog(@"it goes fourth textfield doesn't clear number in cell.");             [textfield resignfirstresponder];             [fourthcodefield becomefirstresponder];             return no;         }     }      return (newlength > 1) ? no : yes; } 

enter image description here

back space has recognized in textfield :shouldchangecharactersinrange:

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string       {         if (string.length == 0 //backspace             && textfield.text.length)//no characters in text field         {             [textfield resignfirstresponder];             return no;         }         return yes;     } 

updated answer. when fifth field empty, clicking space moves fourth field , clears last character in fourth

    - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string     {         nsuinteger newlength = [textfield.text length] + [string length] - range.length;          if (string.length == 0 && textfield.text.length)         {             if(textfield==fifthcodefield) {                 nslog(@"it goes fourth textfield doesn't clear number in cell.");                 [textfield resignfirstresponder];                  //character range last character                 nsrange fourthfieldrange;                 range.length = 1;                 range.location = field.text.length - 1;                  nsstring *text = [fourthcodefield.text stringbyreplacingcharactersinrange:fourthfieldrange withstring:@""];                  [fourthcodefield becomefirstresponder];                 return no;             }         }          return (newlength > 1) ? no : yes;     } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -