I'm a seasoned java programmer with no experience in C or C++ trying to make the jump to Obj-C (what a nightmare), and after a couple days of reading docs, I got started writing my first app, as per the excellent tutorial found here. When the user taps a button, the program updates a label from the contents of a text box. I got done with it, and am trying to add in a simple if statement, to only allow the user to change the label if the text in the text box is not a certain string, in this case "boring". But the program goes ahead as though the if isn't even there. What am I doing wrong here?
I included the two different methods I have tried because neither of them has worked, and as long as I'm here I might as well.
Method 1:
Method 2 (I saved "boring" in a variable):
I included the two different methods I have tried because neither of them has worked, and as long as I'm here I might as well.
Method 1:
Code:
- (IBAction)click:(id)sender;
{
NSString *newText = [textField text];
if (newText != @"boring") {
[label setText:newText];
}
}
Method 2 (I saved "boring" in a variable):
Code:
- (IBAction)click:(id)sender;
{
NSString *newText = [textField text];
NSString *dontCopy = @"boring";
if (newText != dontCopy) {
[label setText:newText];
}
}