以编程方式创建UITextField事件 [英] Programmatically create UITextField events
问题描述
我在创建行时,将一些文本框以编程方式添加到TableView中。我想通过这样做来订阅这些textField的TouchUpInside事件
I some add textfields programmatically into a TableView when the rows are created. I am trying to subscribe to the TouchUpInside event of these textFields by doing this
UITextField *eTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 12, 145, 25)];
eTextField.delegate = self;
[eTextField addTarget:self action:@selector(showPicker)
forControlEvents:UIControlEventTouchUpInside];
showPicker是一个没有参数的IBAction,它永远不会被触发。有没有什么我需要做的?
showPicker is an IBAction with no parameters.It never gets fired. Is there something I else I need to do?
有没有什么我错过的?
提前感谢
Is there something I'm missing? Thanks in advance
推荐答案
如果您尝试显示文本字段而不是键盘的选择器,则应该将选择器选择器视图分配为文本字段的 inputView
。
If you are trying to show a picker for the text field instead of keyboard, you should assign the picker picker view as the inputView
of the text field.
但是,如果要启动某些方法用户触摸文本字段,您应该覆盖
文本字段委托方法
But if you want to fire some method when user touches the text field, you should override the text field delegate method
textFieldDidBeginEditing
textFieldDidBeginEditing
并呼叫第一个响应者,以避免键盘,然后编写您的自定义代码或方法调用。
and call resign first responder to avoid the keyboard, and then write your custom code or method calls.
这篇关于以编程方式创建UITextField事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!