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

时间:2013-10-30 11:39:14

标签: ios objective-c

在完成this query的解决方案之后,当我打印mutableArray时,我得到了日志中的输出,如下所示。

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

其中'Def'是在动态创建的文本字段中输入的文本。我想在登录保存按钮点击中提取'Def'并显示。这是代码

- (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
}

1 个答案:

答案 0 :(得分:3)

- (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); 
}

在创建UITextField时设置标记并使用这样的方法。我希望它对你有用