Navigate through next button in textFields iOS swift
Problem:
I want to navigate to next field that wants to be focusable when i click next button.If i click the end textfield then keyboard wants to be hidden.
Solution:
In textfield delegate method do the following.
Objective c:
Swift:
I want to navigate to next field that wants to be focusable when i click next button.If i click the end textfield then keyboard wants to be hidden.
Solution:
In textfield delegate method do the following.
Objective c:
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSInteger nextTF = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTF];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}
Swift:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
let myTextField = textField.tag + 1
let nextResponder = textField.superview?.viewWithTag(myTextField) as UIResponder!
if nextResponder != nil {
nextResponder?.becomeFirstResponder()
} else {
textField.resignFirstResponder()
}
return false
}
Comments
Post a Comment