我在Xamarin文档中找不到关于导航到表单上一系列文本字段中的下一个文本字段的任何内容,只有一个关于删除键盘的小教程.
为了简单起见,我使用的是txtUsername(标记1)文本字段和txtPassword(标记2)文本字段.当我实现以下代码时,它不会转移到Xamarin Studio.有没有人知道这可以在Xamarin Studio中完成代码的方式,或者如果我可以将代码从XCode传输到Xamarin Studio.
我使用以下代码:
- - (BOOL)textFieldShouldReturn:(UITextField *)txtUsername{
- NSLog(@"textFieldShouldReturn:");
- if (txtUsername.tag == 1) {
- UITextField *txtPassword= (UITextField *)[self.view viewWithTag:2];
- [txtPassword becomeFirstResponder];
- }
- else {
- [txtUsername resignFirstResponder];
- }
- return YES;
- }
提前致谢
解决方法
您可以使用这些功能
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.BecomeFirstResponder
- BecomeFirstResponder()
和
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.ResignFirstResponder
- ResignFirstResponder()
根据文档,您应该像这样添加textField Delegate方法
- public virtual bool ShouldReturn (UITextField textField)
- {
- if (txtUsername.tag == 1) {
- UITextField txtPassword = (UITextField)this.view.ViewWithTag(2);
- txtPassword.BecomeFirstResponder();
- }
- else {
- txtUsername.ResignFirstResponder();
- }
- return true;
- }