iphone 使用 Tag 检查 UITextField 是否存在
有没有办法使用 Tag 属性来检测 UITextField 是否存在?本质上,我有许多动态创建的文本字段,我想使用键盘上的返回键来浏览这些字段。
我正在尝试使用另一篇文章中的以下代码,但“textField.superview”返回 null。我正在以编程方式创建文本字段。
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
Is there a way to detect if a UITextField exists using the Tag property? Essentially i have a number of textfields created dynamically and I want to tab through the fields using the return key on the keypad.
I am trying to use the below code form another post but 'textField.superview' returns null. I am creating the textfields programatically.
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以直接像这样检查
设置标签
You can directly check like this
For setting the tag
您可以使用 isKindofClass: 方法。您可以这样做
You can use isKindofClass: method.You can do like this
您是否设置了文本字段的标签?标签字段不会自动设置,您必须在创建文本字段时自行设置,以便稍后识别。如果你不设置它,它们都默认为 0 - 所以你永远不会找到任何带有文本 > 的字段。 0。
Did you set the Tag of the text fields? The tag field is not set automatically, you have to set it yourself when you create the text field so you can identify it later. If you don't set it, they all default to 0 - so you will never find any field with a text > 0.