I have a UITableView
with sections where when you tap on a section, the section expands and there are options to choose from or you can insert your own option via a UITextField
in one of the UITableViewCells
. For that cell, I have this code in tableView: cellForRowAtIndexPath:
to configure the custom cell and set the first responder.
DataAddTVCell *dataInputcell = (DataAddTVCell *)cell;
dataInputcell.data.delegate = self;
self.dataTextfield = dataInputcell.data;
[self.dataTextfield becomeFirstResponder];
the data field is the UITextField
. I save the UITextField
in self.dataTextField so that I can resignFirstResponder
later.
The first time my DataAddTVCell
is loaded from and expanded section, it works fine and becomes the first responder. Resigning as first responder also works. But when the cell is loaded again when another section is expanded, it doesn't become the first responder. If I tap on the textField
, the keyboard shows up fine and I can resign the first responder in the same way I did before. Not sure why the textField can only become the first responder once. I also have these delegate methods and have set <UITextFieldDelegate
>
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (BOOL)becomeFirstResponder
{
return YES;
}
I'm suspecting that this is happening because I am using dequeueReusableCellWithIdentifier
. Is there any way to make it work while using this? Or will I have to create a new cell every time if I want it to become the first responder always when it shows? That seems pretty bad to create so many cells always though.