ochao ochao - 3 months ago 10
iOS Question

Compare two text fields, iOS


  1. I have two text fields in one view.

  2. I saved one text field in
    NSSUserDefaults
    and load in
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];



I try to compare those two text fields, with a button:

if ([st1 isEqualToString: st2])
{
// do something
}
else
{
// do something else
}


When I run this on my iPhone for test, and I press the button, he give me the }else} do something before I write something.

I wanted check first those two text field isEqualToString when I press the button before write something. and before save something, and after save do

if ([st1 isEqualToString: st2])
{
// do something
}
else
{
// do something else
}

Answer
if([textField1.text isEqualToString:textField2.text])
{
    // do something
}
Comments