pixelbitlabs
pixelbitlabs

Reputation: 1934

How can I create array objects from UITextFields?

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!

Upvotes: 0

Views: 1845

Answers (2)

0x8badf00d
0x8badf00d

Reputation: 6401

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];
}

Upvotes: 1

Joseph DeCarlo
Joseph DeCarlo

Reputation: 3278

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.

Upvotes: 1

Related Questions