简体   繁体   English

如何在tabBar按钮的Action上从一个textFields移动到下一个textField

[英]How to move from one textFields to next textField on tabBar button's Action

In my iphone app I have 6 textFields, and a tabBar (having 3 buttons Next,Previous,Done). 在我的iPhone应用程序中,我有6个textFields和一个tabBar(有3个按钮Next,Previous,Done)。

All I need to do is when I click on next button, the focus should move from first textField to next textField. 我需要做的就是当我点击下一个按钮时,焦点应该从第一个textField移动到下一个textField。

On Next button's IBAction I write the following code : 在Next按钮的IBAction上,我编写以下代码:

if ([txt1 isFirstResponder]==YES) {

    NSLog(@"TXT1");

    [txt1 resignFirstResponder];

    [txt2 becomeFirstResponder];

}
else if ([txt2 isFirstResponder]==YES) {

    [txt2 resignFirstResponder];

    [txt3 becomeFirstResponder];

}
else  if ([txt3 isFirstResponder]==YES) {

    [txt3 resignFirstResponder];

    [txt4 becomeFirstResponder];

}
else  if ([txt4 isFirstResponder]==YES) {

    [txt4 resignFirstResponder];

    [txt5 becomeFirstResponder];

}
else  if ([txt5 isFirstResponder]==YES) {

    [txt5 resignFirstResponder];

    [txt6 becomeFirstResponder];

}
else  if ([txt6 isFirstResponder]==YES) {

    [txt6 resignFirstResponder];

}

when I use this code NSLog prints infinite times. 当我使用这段代码时,NSLog打印无限次。

What can be done?? 可以做些什么?

Might be because if txt1 isFirstResponder , you're setting txt2 as firstResponder, then checking if txt2 is first responder. 可能因为如果txt1 isFirstRespondertxt1 isFirstResponder ,你将txt2设置为firstResponder,然后检查txt2是否是第一响应者。 You should put a break; 你应该break; at the end of each if statement. 在每个if语句的末尾。

Oops, its my mistake. 哎呀,这是我的错。 I Forgot to connect textField's delegate to Files Owner.. Thank you guys. 我忘了将textField的委托连接到文件所有者..谢谢你们。

Actually, in each if statement, you do not need the resignFirstResponder , since you do not want to dismiss the keyboard each time you move to another field. 实际上,在每个if语句中,您不需要resignFirstResponder ,因为每次移动到另一个字段时都不想关闭键盘。

Instead, leave the only resignFirstResponder in txt6 相反,将唯一的resignFirstRespondertxt6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM