I am trying to implement an input form on an iPhone app by using a grouped static table view.
I’m using didSelectRowAtIndexPath to lazily create a textfield and add to the relevant cell.

My problem is that becomeFirstResponder is not behaving as I would expect.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0)
{
if(!self.contactNameTextField)
{
self.contactNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(93, 14, 200, 20)];
self.contactNameTextField.backgroundColor = [UIColor clearColor];
self.contactNameTextField.font = [UIFont boldSystemFontOfSize:15];
self.contactNameTextField.keyboardType = UIKeyboardTypeEmailAddress;
[self.contactNameCell addSubview:self.contactNameTextField];
}
[self.contactNameTextField becomeFirstResponder];
}
if(indexPath.section == 1)
{
if(!self.contactEmailTextField)
{
self.contactEmailTextField = [[UITextField alloc] initWithFrame:CGRectMake(93, 14, 200, 20)];
self.contactEmailTextField.backgroundColor = [UIColor clearColor];
self.contactEmailTextField.font = [UIFont boldSystemFontOfSize:15];
self.contactEmailTextField.keyboardType = UIKeyboardTypeEmailAddress;
[self.contactEmailCell addSubview:self.contactNameTextField];
}
[self.contactEmailTextField becomeFirstResponder];
}
The code steps through as expected.
If I tap section 0 first, the name textfield becomes first responder. If I then tap section 1, the email textfield becomes first responder. If I then tap on section 0, even though becomeFirstResponder is called on the name textfield, it does not respond.
Also, if I tap section 1 first, even though becomeFirstResponder is called on the email textfield, it does not respond.
Please advise
Problem solved, silly cut and paste error with self.contactNameTextField in twice.