How to auto focus (auto tab) to next uitextfield in iPhone? | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

How to auto focus (auto tab) to next uitextfield in iPhone?

Monday

TabIndex changed automatically  on UITextField - iPhone:
                                                                                            That means if you  finished typing first character, the focus should move to the next text field without pressing other key or pressing tab key. For example your password field may need focus on next UITextfield automatically. In my password page each textfield contains one letter, when I type one letter and after that the focus moved to next textfield automatically by using this code snippets .
This is a sample code for AutoFocus to nextUITextField on iphone.
 
 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{       
    NSString *strPassword = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if( [strPassword length] > 0 ){
        textField.text = string;       
        UIResponder* nextResponder = [textField.superview viewWithTag:(textField.tag + 1)];
        if (nextResponder) {
            [nextResponder becomeFirstResponder];
        }       
        return NO;
    }   
    return YES;
}

Note: Don't forget to add Tag for your UITextFiels, before run this code.

0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets