iphone - Check if NSMutableArray contains text from textfield -


i want check if text inserted in textfield in nsmutablearray. let's nsmutablearray has these objects: "hey, hello, no, yes". when user enters text: "hello" want there appear uialertview. have following:

for (int slt = 0; slt < [zouten count]; slt++) {         if (zout.text = [zouten objectatindex:slt]) {              alert = [[uialertview alloc]initwithtitle:@"goedzo!" message:[nsstring stringwithformat:@"je hebt een zout gevonden"] delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];          }     }      [alert show]; 

but somehow message appears every word. doing wrong?

when compare this:

if (zout.text = [zouten objectatindex:slt]) 

you assigning instead of comparing true always.therefore instead of using =, should compare this:

if ([zout.text isequaltostring:[zouten objectatindex:slt]]) 

your code should be:

for (int slt = 0; slt < [zouten count]; slt++) {         if ([zout.text isequaltostring:[zouten objectatindex:slt]]) {             alert = [[uialertview alloc]initwithtitle:@"goedzo!" message:[nsstring stringwithformat:@"je hebt een zout gevonden"] delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];            [alert show];            [alert release];             break;         }     } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -