简体   繁体   English

objective-C:获取以编程方式创建的文本字段的单个字符串

[英]objective-C : get individual strings for textfields created programmatically

After going through the solution for this query , I get the output in the log when i print the mutableArray as shown below. 在完成此查询的解决方案后,当我打印mutableArray时,我在日志中获得输出,如下所示。

*Date Project name :* Save button : (
    Def
)

where 'Def' is the text entered in the textfield created dynamically. 其中'Def'是在动态创建的文本字段中输入的文本。 I want to extract 'Def'and display in log on save button click. 我想在登录保存按钮点击中提取'Def'并显示。 Here's the code 这是代码

- (IBAction)save:(id)sender {
    for(UITextField *field in self.scroll.subviews)
    {
        if([field isKindOfClass:[UITextField class]])
        {
            if([[field text] length] > 0)
            {
                NSMutableArray *mutableTextArray = [[NSMutableArray alloc] init];
                [mutableTextArray addObject:field.text];
                NSLog(@"Save button : %@", mutableTextArray);
                //NSString *str = [str stringByAppendingString:[mutableTextArray objectAtIndex:0]];
                //[self fetchStrings:str];
            }
        }
    }
}

- (void) fetchStrings:(NSString*)enteredString
{
    NSLog("%@", enteredString); //want 'def' to be displayed here
}
- (IBAction)save:(id)sender {
    for(UIView *field in self.scroll.subviews)
    {
        if([field isKindOfClass:[UITextField class]])
        {
            if(((UITextField *)field).text.length > 0)
            {
                [mutableTextArray addObject:field.text];//mutableTextArray declare this locally in Interfacefile and then initialize the array in viewDidLoad

            }
        }
    }
    NSLog(@"%@", mutableTextArray); 
}

While you create UITextField set the Tag and use like this. 在您创建UITextField时设置Tag并使用这样的方法。 I hope it will be work for you 我希望它对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM