Create text boxes.
Hook up IBOutlets for the text boxes (ties the text box to a "name")
write out method for the text boxes
create if statements:
Code:
if (textField == self.textFieldName) {
if (self.textFieldName == nil) {
execute statement
}
}
So if I wanted say 2 text boxes to have values how would I put that in one?
e.g. if (textField == self.textFieldName)
AND (textField2 == self.textFieldName2) {
etc.
would mean that textFieldA must = nil AND textFieldB must = nil for the statement to execute
Yes it would. In fact there are three things that have to != nil.
Basically I want it to detect out of 5 text boxes, which ones actually have values entered and to choose an IBAction accordingly.
Where would I position my If statements in my code?
Yes it would. In fact there are three things that have to != nil.
Basically I want it to detect out of 5 text boxes, which ones actually have values entered and to choose an IBAction accordingly.
Where would I position my If statements in my code?
Please show your code that doesn't work.
__________________ Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
I keep getting an error 'expected (' before the if.
Ok, several things.
You say you keep getting 'expected (' before the if. If you're getting an error before the if statement, you need to post the code that appears before the if statement.
Next: I think you are getting some bad advice about how to check if a field is blank. I'm fairly certain that you will never get nil back from the text property of a text field. You will get an empty string instead.
Second, your code inside the "{" and "}" brackets is the declaration of an IBAction method. That is not valid syntax. You need to put regular statements inside the brackets, not a method declaration.
When do you check to see if these fields are blank and update your result field? On a button push?
If it is on a button push, your code might look like this:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Next: I think you are getting some bad advice about how to check if a field is blank. I'm fairly certain that you will never get nil back from the text property of a text field. You will get an empty string instead.
Kind of two reasons i had gone down that line:
1, Any advice from any forum should get checked over first unless there are a good few of the top posters agreeing on the issue, so here was a way of building in a mistake that could get found and explained by someone else - just as Duncan has and to stop the idea of getting everything done for you .
2, i have had text fields before that when nothing has been entered they have saved a nil value. this was one of the things that caused me a big headache in getting my web service to tie in properly, every time i sent something there would be nil's there from the lack of user input, which in turn later returned the data and displayed "nil" in a bunch of fields - not to snazzy to look at!!
So in my app i now check the text fields like this:
in order to prevent saving "nil" as the "string" that was entered. Maybe its not the most elegant of solutions, but it is one that has been working 100% for me. Looking at Duncan's post though i would preferably switch to his method (app is in review so a bit late now) as it looks slightly more robust than my solution.
You say you keep getting 'expected (' before the if. If you're getting an error before the if statement, you need to post the code that appears before the if statement.
Next: I think you are getting some bad advice about how to check if a field is blank. I'm fairly certain that you will never get nil back from the text property of a text field. You will get an empty string instead.
Second, your code inside the "{" and "}" brackets is the declaration of an IBAction method. That is not valid syntax. You need to put regular statements inside the brackets, not a method declaration.
When do you check to see if these fields are blank and update your result field? On a button push?
If it is on a button push, your code might look like this:
Thanks, this has solved it. Most of my values are working perfectly now!
The only problem now is trying to solve a quadratic in the IBAction...
But that will come later. Thanks!