tableview with text fields in each row having resignkeypad issue - objective-c

i am adding the textfield on each row inside the cellforrow method of tableview,but when i type anything on any textfield ind try to resign textfield on view touch, but it only works for last row's textfield only. what is the solution for that issue,
please help.
Thanks
Dhananjay

if i understand you correctly this will probably work:
add the protocol to your viewController in question and add
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
// custom code
}
afterwards make sure that each textField has your viewController as delegate.

Related

How to get textFields in custom UITableView

Very beginner obj-c question.
I have plain UITableView with two sections, but I am interested only in first section now. This section have four custom cells (inherited from standard UITableViewCell), and they have a UITextField's as a property.
I need to improve custom Input Accessory View with buttons "Next", "Previous"(for switch between textFields in tableview) and "Done" (dismissimg of keyboard). http://uaimage.com/image/62f08045
In -textFieldShouldReturn i set tags for textFields from 0 to 3. My next plan is to add textFields into NSMutableArray in -viewDidLoad and then just set and resign first responder for the textFields. Approximate code listing for "Next" button:
- (void) inputAccessoryViewDidSelectNext:(FDInputAccessoryView *)view {
for (UITextField *textField in [self textFieldsArray]) {
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
UITextField *field = [[self textFieldsArray] objectAtIndex:textField.tag + 1];
[field becomeFirstResponder];
}
}
}
Questions:
Is this a right way or maybe there is a better approach to solve problem?
Do I need to tag textfields or use indexPath of cells in what they are built in? (or what is the best to track textFields?)
And the main question: what is the syntax to "get" textField from cell?
Sorry for the dumb questions, I am a very beginner.
Thanks,
Alex.
I think you have the right idea, but a few things come to mind:
Just to be safe, don't start with tag number 0. Every view has a tag number defaulted to 0, so you may get something unexpected.
Don't set the text view's tags inside of the textFieldShouldReturn, set the tags in cellForRowAtIndexPath or viewDidLoad, wherever you init the textFields.
Add the textFields to the cell's contentView, not the cell itself.
You don't have to resign first responder from the first text field, you can just becomeFirstResponder on the new one.
Make sure you're handling the last text view edge case: You could loop around to the first text field or simply dismiss the keyboard at the end.
If you want to get the textField in the cell:
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:
[NSIndexPath indexPathForRow:ROW_NUMBER inSection:1]];
UITextField *textField = (UITextField *)[cell.contentView viewWithTag:TEXT_FIELD_TAG];

UIVIew endEditing:YES doesnt hide the keyboard

I have a UIVIew which is a subview and it contains several UITextFields. One of these textfields (which is for DATE) should not be editable using the keyboard, instead of this I use a PopOver with a Datepicker inside.
I run a method when the UIControlEventEditingDidBegin is reached. This method calls the resignFirstResponder on the DateTextField.
Everything works fine if the DateTextField is the first field to edit, but when another textField is edited and of course shows the keyboard and then try to edit the DateField, the keyboard doesn't hide and everything goes normal but with the Keyboard doing anything.
I have tried to call the method endEditing:YES before the resignFirstResponder but it doesn't work. I have tried to run the endEditing:YES and resignFirstResponder on the didEndEditing text field method but theres no way to get that keyboard out.
here is my method:
- (void)showDatePopOver:(id)sender{
[self.view endEditing:YES];
UITextField *textField = (UITextField *)sender;
[sender resignFirstResponder]; // hide keyboard
/** POP OVER LINES**/
}
You should use the textFieldShouldBeginEditing: delegate method instead of resigning first responder in didBeginEditing:
This will allow editing on ALL BUT the dateTextField text field:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return (![textField isEqual:dateTextField]);
}
You should specify that your view controller is a text view delegate as well like so (in the interface declaration [.h file]):
#interface MyViewController : UIViewController <UITextFieldDelegate>

UITableView reloadData causes UITextField to resignFirstResponder

I have a textField that is set to change the tableView's dataSource with each letter that's entered (and call reloadData).
But for some reason, every time a letter is entered, the keyboard is dismissed.
Anyone know why?
Your text field is resigning because reloaded cells are sent a -resignFirstResponder message due to the fact that their survival is not guaranteed after a reload. See this related question for more.
Use this method textFieldShouldReturn: and add UITextFieldDelegate delegate in yourClass.h file. set delegate to yourTextfield and write following code in viewDidLoad method.
yourTextfield.delegate = self;
and also implement the textFieldShouldReturn: as following as
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
I think it will be helpful to you.

Make "Done" button work on TextField Keyboard

When adding a textfield, the keyboard opens correctly, however I cannot get the done button to work properly. I know thee are other similar posts, however for whatever reason they do not seem to work for me.
When I say "not work" i mean the keyboard does not close.
Any suggestions would be appreciated.
Add this and let me know:
- (BOOL)textFieldShouldReturn:(UITextField*)aTextField
{
[aTextField resignFirstResponder];
return YES;
}
Remember to add the viewController as delegate of your text field
I believe this is what you're looking for. Its a UITextFieldDelegate callback thats called anytime the Done/Return button is used on the keyboard.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
You'll need the delegate in your interface
#interface Class : UIViewController <UITextFieldDelegate>
If you're textfield is in a ModalViewController using the FormSheet style you need this as well.
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}

Show keyboard with a UIPopover

How can I show the keyboard when my popover shows up?
The popover is UIViewController that I call from a popoverController.
The popover has an UITextField and when the popover is displayed, the keyboard need to show up too and the cursor go to the UITextfield.
I tried to put the becomeFirstResponder under viewDidLoad or viewWillLoad, and not work.
[userValue becomeFirstResponder];
What I miss?
That's all folks. Thanks.
You need to make the textField the first responder, not the popover itself. Just because you make an object the first responder, doesn't mean it will show the keyboard. It needs to be an object with text entry properties, like a UITextField, to display the keyboard.
- (void)viewDidAppear:(BOOL)animated{
[_textField becomeFirstResponder];
[super viewDidAppear:animated];
}
You can call the method above if you want that particular textField to be the first responder, with keyboard, each time the popover is displayed. Remember, this method is called AFTER the popover is loaded.
Hope this helps.
Assign the first responder in the viewWillAppear method.
i think u didn't set the textfield delegates to self and trying putting breakpoints and check what is happening ,is it even going to textfield delegates or not.