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 に答える