ios - 如何获取文本字段值并通过该文本字段的标记值调用它们

标签 ios objective-c uialertcontroller

我有两个文本字段。我没有全局声明。所以它在我的 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/

相关文章:

ios - 使用动态大小的单元格限制 UICollectionView 的数量

ios - 将核心数据作为对象读取

iphone - 如何 - (CGRect)convertRect :(CGRect)rect toView:(UIView *)view work

ios - 可以在模态视图 Controller 上使用 UIAlertController 吗?

android - ionic 构建到/dist 文件夹而不是/www

ios - 从导航栏 View Controller 导航到标签栏 View Controller

android - 在线播放多首音频

iphone - 以不同方式格式化 UILabel 中的文本

swift - 从 uiAlertController 中的文本字段检索内容

ios - 如何增加 UIAlertAction 中的 Alpha?