UITextfield 成为第一响应者不工作
我的键盘顶部有一个工具栏,带有上一个和下一个按钮。当我按下下一个按钮时,下一个文本字段应该成为第一响应者,但这种情况不会发生。这是我的代码。
-(IBAction) nextfield {
if([name isFirstResponder] == TRUE) {
[name resignFirstResponder];
[surname becomeFirstResponder];
if(surname.editing == TRUE)
NSLog(@"surname");
}
if([surname isFirstResponder] == TRUE) {
[email becomeFirstResponder];
}
if([email isFirstResponder] == TRUE) {
[password becomeFirstResponder];
}
if([password isFirstResponder] == TRUE) {
[confirm becomeFirstResponder];
}
if([confirm isFirstResponder] == TRUE) {
[country becomeFirstResponder];
}
if([country isFirstResponder] == TRUE) {
if(country.text == @"United States") {
[state setEnabled:TRUE];
[state becomeFirstResponder];
}
else {
[type becomeFirstResponder];
}
}
if([state isFirstResponder] == TRUE) {
[type becomeFirstResponder];
}
if ([type isFirstResponder] == TRUE) {
[name becomeFirstResponder];
}
}
我进入“姓氏”日志,但光标不显示,如果我输入某些内容,它不会出现在任何地方。
I have a toolbar on top of the keyboard with a prev and next button. When I press the next button the next textfield should become first responder but this doesn't happen. Here is my code.
-(IBAction) nextfield {
if([name isFirstResponder] == TRUE) {
[name resignFirstResponder];
[surname becomeFirstResponder];
if(surname.editing == TRUE)
NSLog(@"surname");
}
if([surname isFirstResponder] == TRUE) {
[email becomeFirstResponder];
}
if([email isFirstResponder] == TRUE) {
[password becomeFirstResponder];
}
if([password isFirstResponder] == TRUE) {
[confirm becomeFirstResponder];
}
if([confirm isFirstResponder] == TRUE) {
[country becomeFirstResponder];
}
if([country isFirstResponder] == TRUE) {
if(country.text == @"United States") {
[state setEnabled:TRUE];
[state becomeFirstResponder];
}
else {
[type becomeFirstResponder];
}
}
if([state isFirstResponder] == TRUE) {
[type becomeFirstResponder];
}
if ([type isFirstResponder] == TRUE) {
[name becomeFirstResponder];
}
}
I get in Log "surname" but the cursor doesn't show up and if i type something it doesn't appear anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,您要检查 name 是否是第一响应者,如果是,则将 surname 设置为第一响应者。
然后您检查姓氏是否是第一响应者,如果是,则将电子邮件设置为第一响应者。
然后你检查电子邮件是否是第一响应者,如果是……
你的问题是这些 if 语句中的每一个都是正确的,因为成为第一响应者是立即发生的事情。
换句话说,您应该使用 else if (...) 语句而不是离散的 if 语句。
So you're checking to see if name is the first responder, and if it is, then making surname the first responder.
Then you check and see if surname is the first responder, and if it is, you make email the first responder.
Then you check and see if email is the first responder, and if it is....
Your problem is that every one of those if statements is true, because becoming first responder is an immediate thing.
In other words, you should be using
else if (...)
statements instead of discrete if statements.创建一个文本字段对象数组,比如 textFieldArray。然后在上一个和下一个按钮选项卡上调用以下函数
create an array of textfield object lets say textFieldArray. then on prev and next button tab call following func