1

在完成此查询的解决方案后,当我打印 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
}
4

1 回答 1

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 时设置标签并像这样使用。我希望它对你有用

于 2013-10-30T11:44:15.623 回答