0

I have a number of textfields in a view, and a textView, what I am trying to do is to tab through those UI elements after editing stops and the element resigns the status as FirstResponder.

//Code to tap on empty area on screen so key board should disappear

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
   [self.view endEditing:YES];    
} 

//a text field should now be the first responder after text area should end editing

-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
    [self.txtNumber becomeFirstResponder];
    return YES;
}

Problem comes after the following steps 1. textView becomes first responder 2. tap outside textview resigns as first responder 3. txtNumber becomes first responder and numpad appears 4. tap outside. now keyboard doesn't disappear

mdanishs
  • 1,996
  • 8
  • 24
  • 50

2 Answers2

1

Use:

@implementation ViewController
    NSNumber *tabCount;

    -(void) viewDidLoad
    {
       tabCount = 0;
    }

   -(void)textViewDidBeginEditing:(UITextView *)textView
    {
        if([tabCount integerValue] ==0)
         [self.txt0 becomeFirstResponder];
        if([tabCount integerValue] ==1)
          {
           [self.txt0 resignFirstResponder];
           [self.txt1 becomeFirstResponder];
           }
        return YES;
     }
    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
     {
          if ([text isEqualToString:@"\n"]) 
               tabCount = tabCount + 1;
     }
@end

The same concept can be done for UITextField using:

    -(void)textFieldDidBeginEditing:(UITextField *)textField 
    -(BOOL)textFieldShouldReturn:(UITextField*)textField
Janani M
  • 423
  • 3
  • 13
0

try following method may be useful

if you are using present model view controller

- (BOOL)disablesAutomaticKeyboardDismissal {

return NO;

}
Developer
  • 760
  • 3
  • 15