我有两个文本字段。我没有全局声明。所以它在我的 UIAlertController
中。现在 textFields
是:
text.tag = 100
text2.tag = 200
所以我有一个用于 textfield2
的选择器方法,在该方法中我需要调用 textfield1
值是否具有字符串 (hello)。这是我的代码:
问题已编辑 --
最佳答案
喜欢
选择-1
you can access Direct Tags
-(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
you can access Via Object Name
-(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
I have two text field.I din't globally declared. - for your Concept then Do like
- (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
}
}
}
关于ios - 如何获取文本字段值并通过该文本字段的标记值调用它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911261/