1. You have:
if (textField.text = @"Carolyn")
in your code. Did you actually mean:
if (textField.text == @"Carolyn")
Since = will assign @"Carolyn" to textField.text
2. Compared to ==, I guess it's better to use
if([textField.text isEqualToString:@"Carolyn"])
Quote:
Originally Posted by ShayansMind
Someone please help me on this, its 12 AM and I still can't figure this out....
I have a textfield and a label...when ever I type something in the field.text automatically changes to "Carolyn"
*Is there a way to allow both "if" statements to work?
Code:
-(IBAction)analyze:(id)sender {
if ([textField.text length] >= 2) {
int text = rand() % 3;
switch (text) {
case 0:
chill.text = @"Your so chill" ;
break;
case 1:
chill.text = @"you wishh" ;
break;
case 2:
chill.text = @"haha, not even" ;
break;
default:
break;
}
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Please input your name" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
[alert release];
}
if (textField.text = @"Carolyn") {
chill.text = @"Carolyn, pretty darn chill; duuuhhh";
}
}
|