views:

606

answers:

1

I have a custom TableView cell that contains a TextField and I want it to become the first responder as soon as the view is shown but [textcell.textfield becomeFirstResponder] does not work. I know it's because it's a custom cell in another class and I even tried it there and it didn't work. Anyone know how to pull this off?

Thanks...

A: 

I have a similar setup and becomeFirstResponder seems to work fine.

My custom cell:

@interface CustomCell : UITableViewCell 
{
    IBOutlet UITextField *costField;
}

And the delegate method from the controller class:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* CellTableIdentifer = @"CellTableIdentifer";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellTableIdentifer];
    if (cell == nil)
    {
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
     cell = [nib objectAtIndex:0];
    }

    NSUInteger row = [indexPath row];
    ReceiptItem *receiptItem = [models objectAtIndex:row];
    if (receiptItem == justAddedItem)
    {
     [cell.costField becomeFirstResponder];
     justAddedItem = nil;
    }

justAddedItem is set when the user clicks the button to add a new row to the table.

Dara Kong