以编程方式创建 UITextField 事件
我在创建行时以编程方式将文本字段添加到 TableView 中。我试图通过执行此操作来订阅这些文本字段的 TouchUpInside 事件
UITextField *eTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 12, 145, 25)];
eTextField.delegate = self;
[eTextField addTarget:self action:@selector(showPicker)
forControlEvents:UIControlEventTouchUpInside];
showPicker 是一个没有参数的 IBAction。它永远不会被触发。还有什么我需要做的吗?
我有什么遗漏的吗? 提前致谢
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不应该是 [eTextField addTarget:self action:@selector(showPicker*:*)
另外,您也没有分配 UIControlEvent。
所以:
可能应该改为
Shouldn't it be [eTextField addTarget:self action:@selector(showPicker*:*)
Also you are not assign a UIControlEvent.
So:
Should probably be changed in to
如果您尝试显示文本字段的选取器而不是键盘,则应将选取器选取器视图指定为文本字段的
inputView
。但是,如果您想在用户触摸文本字段时触发某些方法,您应该覆盖
文本字段委托方法
并调用 resign 第一响应者以避免键盘,然后编写您的自定义代码或方法调用。
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
and call resign first responder to avoid the keyboard, and then write your custom code or method calls.
您可以尝试这个...
1.覆盖
viewController.m
文件中的textFieldDidEndEditing
。请参阅下面的示例代码:
删除。
2.从代码中
You can try this...
1.Override
textFieldDidEndEditing
in yourviewController.m
file.See the example code below:
2.Remove
from your code.