Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MickeyT

macrumors member
Original poster
Apr 26, 2010
92
0
Newcastle, United Kingdom
Hello all

I have a view with several textfields on it that I want to test for nullstrings when a user presses a button.

Currently I have several if statements that check this, but I was wondering how you would use the "for each" looping to cycle through them all instead and cut down on code.

Does the view conform to a hierarchical structure so that, for example, the textfields are contained within the view? If this is the case then I perceived it to be something like:

foreach(UITextView in UIView) {

............code here......

}

Is this correct - how would it actually be written?

Many thanks for any help.

Cheers.
 
UIView is not a container (directly) so you can't do that. You could use foreach to iterate of the the subviews property but you'd have to check each item to see if it was a UITextView. The compiler won't automatically do that for you.
 
Instead of doing that jst do something like this:

Code:
for (UItextField *textField in myTextFieldView)
{
    //do whatever here
}

Although if your view contains anything other than text fields youll want to change UITextField *textField to UIView *view and then make sure you only do the actions for the text fields.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.