objective c - While (not) loop freezes app -
my while loop doesn't seem work. when loading view, app freezes. when delete part of code, containing while loop, app won't freeze.
what i'm searching piece of code cause same array not chosen twice.
@interface thirdviewcontroller () @end @implementation thirdviewcontroller ... nsstring * answer = @""; nsarray * ramarray; ... - (void)newquestion { nsstring * pliststring = [[nsbundle mainbundle] pathforresource:@"questions" oftype:@"plist"]; nsmutablearray * plistarray = [[nsmutablearray alloc]initwithcontentsoffile:pliststring]; nsarray *plistrandom = [plistarray objectatindex: random()%[plistarray count]]; while (![plistrandom isequal: ramarray]) { nsarray *plistrandom = [plistarray objectatindex: random()%[plistarray count]]; } ramarray = plistrandom; ... } - (void)check:(nsstring*)choise { ... if ([choise isequaltostring: answer]) { ... [self newquestion]; } } - (ibaction)ansbuta:(id)sender { uibutton *resultbutton = (uibutton *)sender; nsstring *click = resultbutton.currenttitle; [self check:click]; }
my guess because re-declare plistrandom
within while loop, inner-declared variable may out of scope @ point while
conditionis evaluated. problem think scoping issue, change loop , see if works:
while (![plistrandom isequal: ramarray]) { plistrandom = [plistarray objectatindex: random()%[plistarray count]]; }
Comments
Post a Comment