我有两个textFields。我没有全局声明。所以它在我的UIAlertController
。现在textFields
是:
text.tag = 100
text2.tag = 200
所以我有一个选择器方法要textfield2
在该方法中我需要调用textfield1
值是否有字符串(hello)。这是我的代码:
问题已编辑-
喜欢
选择1
您可以访问直接标签
-(void)textDidChange:(UITextField *)textField
{
if (textField.text.length > 0) {
if (textField.tag == 100) // textField1
{
if ([textField.text containsString:@"@"])
NSLog(@"Valid");
else
NSLog(@"Invalid");
}
else
{
//textField2 work
}
}
}
选择2
您可以通过对象名称访问
-(void)textDidChange:(UITextField *)textField
{
if (textField.text.length > 0) {
if (textField == textField1) // 100
{
if ([textField.text containsString:@"@"])
NSLog(@"Valid");
else
NSLog(@"Invalid");
}
else
{
//textField2 work
}
}
}
选择3
我有两个文本字段。我没有全局声明。-为您的概念,然后喜欢
- (void)textDidChange:(UITextField *)sender
{
UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
if (alertController)
{
UITextField *txt1 = alertController.textFields.firstObject;
UITextField *txt2 = alertController.textFields.lastObject;
if (textField.text.length > 0) {
if (textField == txt1) // 100
{
if ([textField.text containsString:@"@"])
NSLog(@"Valid");
else
NSLog(@"Invalid");
}
else
{
//textField2 work
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句