Search code examples
listviewuitextfieldbecomefirstresponder

UITextField becomeFirstResponder does not work


I have a listview on the bottom part of the screen and a 4 field entry form at the top part of the screen. When I tap on the list item I would like to set focus to the 1st text field.

I have the code like this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:(NSIndexPath *)indexPath
{

    ....
    ....
    else if(editingStyle == UITableViewCellEditingStyleInsert)
        {
               [self clrscreen];

               [oDescription becomeFirstResponder];
            }

but it doesnt work. Do I have to get the focus out of the listview first or something


Solution

  • Maybe in the

    [self clrscreen];
    

    method you process the UI and the UITableView is redrawn. If that is so, at the moment you call the

    [oDescription becomeFirstResponder];
    

    it is not there. Please check if oDescription is not nil .

    One more thing: where/when is this called:

    ....
    ....
    else if(editingStyle == UITableViewCellEditingStyleInsert) ?