1

After going through the solution for this query, I get the output in the log when i print the mutableArray as shown below.

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

where 'Def' is the text entered in the textfield created dynamically. I want to extract 'Def'and display in log on save button click. 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
}
3
  • mutableTextArray should be instance level variable and not local. Then it will be accessible across instance methods. Commented Oct 30, 2013 at 11:42
  • @Deepak Thakur your log is not readable..can you post a screenshot mr. Commented Oct 30, 2013 at 11:49
  • i get that by using this NSLog(@"Save button %@", mutableTextArray); Commented Oct 30, 2013 at 11:55

1 Answer 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); 
}

While you create UITextField set the Tag and use like this. I hope it will be work for you

Sign up to request clarification or add additional context in comments.

6 Comments

i think u must have an array inside the innermost if condition. calling method directly is not working.
@DeepakThakur - (void) fetchStrings:(NSString*)enteredString; declare this in your interface file it will call this method
@DeepakThakur:Set break point inside this if(((UITextField *)field).text.length > 0) and check the condition satisfies or not?
it works after removing tag==100. Also, adding break will give me only the first textfields data. I need to handle the remaining ones also..
i need to change the parameter of fetchStrings from nsstring to nsarray to get all values
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.