这是转到下一个 UITextField (使用 textFieldShouldReturn)的一种黑客方式吗?
- (BOOL)textFieldShouldReturn:(UITextField *)sender
{
if(sender.returnKeyType == UIReturnKeyNext){
// Make something else first responder
}else if(sender.returnKeyType == UIReturnKeyGo){
// Do something
}else{
[sender resignFirstResponder];
}
return YES;
}
我有一个 UITextFieldDelegate 使用这个。我是 iPhone 开发新手。来自网络,我习惯于动态且最小化地定义事件。这是从用户名到密码 UITextFields 的“好”方法吗?
有更好的通用做法吗?
- (BOOL)textFieldShouldReturn:(UITextField *)sender
{
if(sender.returnKeyType == UIReturnKeyNext){
// Make something else first responder
}else if(sender.returnKeyType == UIReturnKeyGo){
// Do something
}else{
[sender resignFirstResponder];
}
return YES;
}
I have a UITextFieldDelegate using this. I'm new to iPhone dev stuff. Coming from web, I'm used to defining events dynamically and minimally. Is this an "ok" way to go from Username to Password UITextFields?
Is there a better common practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此处已对此进行了广泛讨论:如何浏览文本字段(下一步/完成)按钮)
但快速回答是肯定的,这很好!没什么奇怪的。
This has been discussed extensively here: How to navigate through textfields (Next / Done Buttons)
But the quick answer is yes, this is fine! Nothing hacky about it.
如果您将文本字段声明为类的属性,则只需将发件人与每个文本字段进行比较即可确定正确的操作过程。我可能会做这样的事情。
If you have the text fields declared as properties of the class, you could simply compare sender to each text field to determine the correct course of action. I would probably do something like this.