iphone - Why doesn't the UIAlertView work? -


i testing piece of code when run it, not trigger uialertview. when code hits if (ongoinggame = yes) , nslog jumps directly 'otherbuttontitles:nil' without executing uialertview.

can please explain me why not trigger it?

    -(ibaction)continuegame_button:(id)sender {     //=====check if there on-going game, if continue=====//     accesscurrentgamedata *isthereanongoinggamefunction = [accesscurrentgamedata new];     bool ongoinggame = [isthereanongoinggamefunction checkifgameongoing];     [isthereanongoinggamefunction release];     nslog(@"+ + +continuegame_button+ + +");     nslog(@"ongoinggame = %@\n", (ongoinggame ? @"yes" : @"no"));      if (ongoinggame == yes) {         nslog(@"++++++++++++++++++");         nslog(@"++++++++++++++++++");         nslog(@"++++++++++++++++++");         nslog(@"++++++++++++++++++");         nslog(@"++++++++++++++++++");          //          uialertview *continuegame = [[uialertview alloc] initwithtitle:@"fortsätta spel"                                                               message:@"det finns ett aktivt spel, klicka spela eller tillbaka"                                                              delegate:self                                                      cancelbuttontitle:@"tillbaka"                                                      otherbuttontitles:nil];          [continuegame show];         [continuegame release];       }      exit(0); } 

your alert code just fine use form (three lines - init, show, release) of time alerts.

i suggest exit(0) root of problem. if want exit after user closes alert, should assign delegate close app when user taps on close button. use code, remove exit(0). implement uialertviewdelegate follows:

-(ibaction)continuegame_button:(id)sender {     //=====check if there on-going game, if continue=====//     accesscurrentgamedata *isthereanongoinggamefunction = [accesscurrentgamedata new];     bool ongoinggame = [isthereanongoinggamefunction checkifgameongoing];     [isthereanongoinggamefunction release];     nslog(@"+ + +continuegame_button+ + +");     nslog(@"ongoinggame = %@\n", (ongoinggame ? @"yes" : @"no"));      if (ongoinggame == yes) {         nslog(@"+++++++++ ongoing game +++++++++");          //          uialertview *continuegame = [[uialertview alloc] initwithtitle:@"fortsätta spel"                                                               message:@"det finns ett aktivt spel, klicka spela eller tillbaka"                                                              delegate:self                                                      cancelbuttontitle:@"tillbaka"                                                      otherbuttontitles:nil];          [continuegame show];         [continuegame release];     } }  - (void) alertviewcancel:(uialertview *)alertview{   //if have other alerts, may want check title of alert   //make sure exit when alert dismissed     exit(0); } 

dont' forget add <uialertviewdelegate> code header (.h) file.

you can use - (void) alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex, if want multiple buttons, 1 of them being specific "quit" button.

please note apple discourages using exit() in apps released app store, , using might app rejected.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -