How to move from one textFields to next textField on tabBar button's Action
In my iphone app I have 6 textFields, and a tabBar (having 3 buttons Next,Previous,Done).
All I need to do is w开发者_JS百科hen I click on next button, the focus should move from first textField to next textField.
On Next button's IBAction I write the following code :
if ([txt1 isFirstResponder]==YES) {
NSLog(@"TXT1");
[txt1 resignFirstResponder];
[txt2 becomeFirstResponder];
}
else if ([txt2 isFirstResponder]==YES) {
[txt2 resignFirstResponder];
[txt3 becomeFirstResponder];
}
else if ([txt3 isFirstResponder]==YES) {
[txt3 resignFirstResponder];
[txt4 becomeFirstResponder];
}
else if ([txt4 isFirstResponder]==YES) {
[txt4 resignFirstResponder];
[txt5 becomeFirstResponder];
}
else if ([txt5 isFirstResponder]==YES) {
[txt5 resignFirstResponder];
[txt6 becomeFirstResponder];
}
else if ([txt6 isFirstResponder]==YES) {
[txt6 resignFirstResponder];
}
when I use this code NSLog prints infinite times.
What can be done??
Might be because if txt1 isFirstResponder
, you're setting txt2 as firstResponder, then checking if txt2 is first responder. You should put a break;
at the end of each if
statement.
Oops, its my mistake. I Forgot to connect textField's delegate to Files Owner.. Thank you guys.
Actually, in each if statement, you do not need the resignFirstResponder
, since you do not want to dismiss the keyboard each time you move to another field.
Instead, leave the only resignFirstResponder
in txt6
精彩评论