After you designate your view controller as a UITextField delegate, you can access the values ββof the text fields at different points using the delegate methods below:
β textFieldShouldBeginEditing: β textFieldDidBeginEditing: β textFieldShouldEndEditing: β textFieldDidEndEditing:
As an example, in any of these methods you can get the value of textField.text and assign it to NSString, which can be passed to your LOGIN method as needed.
Assuming your login text field has a tag value of 1, and your password text field has a tag value of 2, you can capture the values ββusing the delegation method below:
- (void) textFieldDidEndEditing:(UITextField *)textField { switch (textField.tag) { case 1: loginString = textField.text; break; case 2: passwordString = textField.text; break; default: break; } }
You can also capture the links of the corresponding cell and indexPath in any of the above methods using:
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell*)[[textField superview] superview]];
And then into the cell with:
UITableViewCell *cell = (UITableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
This would be especially useful if you had a long shape and you want to go to the next field so that the keyboard is not at the top of the cells where you need to enter text. You can also use these links to move the RETURN key on your keyboard to the next UITextField or possibly change the first responder if the user has finished editing the last field of the form.
Hope this makes sense. Hurray, Horn
source share