I want to enter text into a text field and based on the text (if it says “No”) I want the alertview to pop up. I’ve created a UITextField in interface builder and attached it to the UITextField delegate in the files owner so that’s all taken care of. But when I enter text into the text field, specifically no, and click out of the textfield or remove the keyboard, no alertview pops up. I have created an entire method for this within the viewcontroller.m file. Here is the code for that method.
-(void)engageAlert {
if (myTextField.text == @"No") {
theAlertView = [[UIAlertView alloc] initWithTitle:@"Notice" message:@"MyMessageHere"
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[theAlertView show];
}
}
Am I missing something here? Nothing happens when I type No into the textfield.
I think the culprit will be the line
Since you’re comparing two pointers which will never match.
@”No” = 0x12341234 or whatever address for the static address of the NSString (@”” can be thought of as short hand for the compiler creating the NSString object)
What you will want is something like
Also check you’re not going to leak memory with theAlertView as I can’t see where you’re freeing that in the snippet.