views:

71

answers:

1

I have a custom uitableviewcell. It has a uitextfield. I'd like the parent tableview controller to take action when the uitextfield keyboard return key is pressed. How do I get the notification to the parent tableview without creating an app wide event notification? Or, is that the best way?

+2  A: 

If you make your view controller class the delegate for both your UITextField and your UITableView, you don't need to use notifications. Call -setDelegate:self on your UITextField once you've loaded the cell from the xib. Then, in the delegate class (probably your view controller class) implement this:

- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
    if (textField == textFieldInTheTableCell)
    {
        // Do something with your UITableView
    }
    return YES;
}

Your view controller will need to implement the UITextFieldDelegate protocol.

Matt Long