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

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
hi all. Lets say i have a register form and it has around 15 UITextfields and all of them has to be filled. How i can check if they are empty or not ? I checked like
Code:
if (definition.length > 0) {
            if (city.length > 0) {
                if (district.length > 0) {
                    if (address.length > 0) { 
                    }else {
                    }
} else {
}else {
}
}else {
}
}

IS there any easier way to do that ?
 
You can make an array of the textfields and iterate over the array checking the length. That would give you a true/false value of whether all of the textfields have contents.
 
+1 on the array, you can also do a table, but array is quick and easy.
One thing I was going to suggest is that you double check the meaning of 'empty' as I ran into an issue using the length vs isEmpty() or .field == '' or whatever else is an option. You might get different answers and this thru me off a few years ago. I don't remember the details, but you should double check how empty is defined by each method.
 
You can make an array of the textfields and iterate over the array checking the length. That would give you a true/false value of whether all of the textfields have contents.
This suggestion worked perfectly. Thank you man.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.