开发者

Listening for events from a tableviewcell

开发者 https://www.devze.com 2022-12-16 11:16 出处:网络
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 p

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消