Listening for events from a tableviewcell
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 withou开发者_运维知识库t creating an app wide event notification? Or, is that the best way?
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.
精彩评论