Xamarin iOS – 使用返回键导航到下一个文本字段

前端之家收集整理的这篇文章主要介绍了Xamarin iOS – 使用返回键导航到下一个文本字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Xamarin文档中找不到关于导航到表单上一系列文本字段中的下一个文本字段的任何内容,只有一个关于删除键盘的小教程.

为了简单起见,我使用的是txtUsername(标记1)文本字段和txtPassword(标记2)文本字段.当我实现以下代码时,它不会转移到Xamarin Studio.有没有人知道这可以在Xamarin Studio中完成代码的方式,或者如果我可以将代码从XCode传输到Xamarin Studio.

我使用以下代码

  1. - (BOOL)textFieldShouldReturn:(UITextField *)txtUsername{
  2. NSLog(@"textFieldShouldReturn:");
  3. if (txtUsername.tag == 1) {
  4. UITextField *txtPassword= (UITextField *)[self.view viewWithTag:2];
  5. [txtPassword becomeFirstResponder];
  6. }
  7. else {
  8. [txtUsername resignFirstResponder];
  9. }
  10. return YES;
  11. }

提前致谢

解决方法

您可以使用这些功能

http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.BecomeFirstResponder

  1. BecomeFirstResponder()

http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.ResignFirstResponder

  1. ResignFirstResponder()

根据文档,您应该像这样添加textField Delegate方法

  1. public virtual bool ShouldReturn (UITextField textField)
  2. {
  3.  
  4. if (txtUsername.tag == 1) {
  5.  
  6. UITextField txtPassword = (UITextField)this.view.ViewWithTag(2);
  7.  
  8. txtPassword.BecomeFirstResponder();
  9. }
  10. else {
  11. txtUsername.ResignFirstResponder();
  12. }
  13. return true;
  14. }

猜你在找的iOS相关文章