Objective c IOS:使用iPad键盘的enter键进行操作
我有两个文本字段,在第一个文本字段中我写“你好”,当我在iPad键盘上按enter键时,我希望在第二个文本字段中显示“世界”;如何使用enter在应用程序中创建操作?您通常会将视图控制器指定为文本字段的委托,然后实现Objective c IOS:使用iPad键盘的enter键进行操作,objective-c,xcode,ios,ipad,uitextfield,Objective C,Xcode,Ios,Ipad,Uitextfield,我有两个文本字段,在第一个文本字段中我写“你好”,当我在iPad键盘上按enter键时,我希望在第二个文本字段中显示“世界”;如何使用enter在应用程序中创建操作?您通常会将视图控制器指定为文本字段的委托,然后实现文本字段shouldReturn:方法,例如: - (BOOL)textFieldShouldReturn:(UITextField *)textField { otherTextField.text = @"World" return YES; } 您可以通过在控
文本字段shouldReturn:
方法,例如:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
otherTextField.text = @"World"
return YES;
}
您可以通过在控制器中实现协议来实现这一点。例如,您可以执行以下操作:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == theFirstTextField && [textField.text isEqualToString:@"Hello"]) {
theSecondTextField.text = @"World";
}
return YES;
}
将视图控制器设置为textfield的委托,然后实现
-(BOOL)textFieldShouldReturn:(UITextField *)textField
当按下键盘上的“回车”按钮时,会调用该命令。这大致就是您要做的。调整设备类型周围的条件(如果您确实只想要iPad):
啊,好吧,我没有写textfield.delegate=self;Swift中的封装外形为
func textField应返回(textField:UITextField)->Bool
#pragma mark - UITextField Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.firstTextField && [textField.text isEqualToString:@"Hello"]) {
self.secondTextField.text = @"World";
}
return YES;
}