0

How can I create array objects from UITextFields? I also want an if statement for each object to check if the UITextField's text length is more than 1.

How can I do this using this core code?:

maincelltext = [[NSArray alloc] initWithObjects:@"UITextField 1 Content Here",@"UITextField 2 Content Here",@"UITextField 3 Content Here",@"UITextField 3 Content Here",nil];

Thanks!

2 Answers 2

1

Use NSMutableArray instead, and addObject: if(textField1.text.length > 1) then [yourMutableArray addObject:textField1.text]; and so on...

Something like this:

// in your interface
UITextField * textField1;
UITextField * textField2;
UITextField * textField3;

NSMutableArray * mainCellTextArray;

//implementation

mainCellTextArray = [[NSMutableArray alloc] init]; // release it later

if(textField1.text.length > 1)
{
  [mainCellTextArray addObject:textField1.text];
}
if(textField2.text.length > 1)
{
  [mainCellTextArray addObject:textField2.text];
}
if(textField3.text.length > 1)
{
  [mainCellTextArray addObject:textField3.text];
}
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of creating an NSArray, I would use a IBOutletCollection and add all the UITextFields to it. You can do this easily through Interface Builder. To loop through and check that each has a text length of more than one is easily done whether you use NSArray or IBOutletCollection. Just use any of the many looping constructs (i.e. for, for-in) and check each item's text property's length.

Comments

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.