Monday, 15 July 2013

objective c - for loop with array ios -



objective c - for loop with array ios -

i have find way check (at touch of button) if text in textfield nowadays in xml file.

i thought if load xml file array utilize loop see if same result in array.

are not @ practical loops, explain me how can write code kind of problem?

i want if object not nowadays in whole array show alert

thanks

- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. cose = [[nsarray alloc] initwithobjects:@"giovanni",@"giulio",@"ciccio",@"panzo", nil]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } -(ibaction)prova { (nsstring *myelement in cose) { if ([myelement isequaltostring:textfield1.text]) { label1.text = textfield1.text; } else { uialertview *alertcellulare = [[uialertview alloc] initwithtitle:@"attenzione!" message:@"connessione assente" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alertcellulare show]; } } }

with fast-enumeration:

-(ibaction)prova { bool nowadays = no; (nsstring *myelement in cose) { if ([myelement isequaltostring:textfield1.text]) { label1.text = textfield1.text; nowadays = yes; break; } } if (!present){ uialertview *alertcellulare = [[uialertview alloc] initwithtitle:@"attenzione!" message:@"connessione assente" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alertcellulare show]; } }

with block based enumeration

-(ibaction)prova { __block bool nowadays = no; [cose enumerateobjectsusingblock:^(nsstring *name, nsuinteger idx, bool *stop){ if ([name isequaltostring:textfield1.text]) { label1.text = textfield1.text; nowadays = yes; *stop = yes; } }]; if (!present){ uialertview *alertcellulare = [[uialertview alloc] initwithtitle:@"attenzione!" message:@"connessione assente" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alertcellulare show]; } }

ios objective-c cocoa-touch for-loop

No comments:

Post a Comment