0

I have a problem with UIAlertView i do not understand. I cannot get it to work. I have changed the code during test so the UIAlertView should hit directly when pressing the button.

I have tested with breakpoint/debugger and what is happening when i press the button is that the first line that it stops at is "otherButtonTitles:nil];".

I did test the piece of code in an other part of the app and it worked.

I have no idea what i am doing wrong.

- (IBAction)startNewGame_Button:(id)sender {

    UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:@"VARNING"
                                                             message:@"Ingen spelare är vald!\n \n Välj spelare och försök igen!" 
                                                            delegate:nil 
                                                   cancelButtonTitle:@"OK" 
                                                   otherButtonTitles:nil];
    [noPlayersAlert show];
    [noPlayersAlert release];

    ...
}

==============UPDATE=====================

When i copy this code to another button it works??

Here it is in one line, tested that with the same result:

UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:@"VARNING" message:@"Ingen spelare är vald!\n \n Välj spelare och försök igen!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

==============UPDATE #2==================

Problem solved, even if i do not understand the reason, as i removed an "exit(0)" i had far below the UIAlertView during the testing.

Thanks to all of you who answered :)

PeterK
  • 4,243
  • 4
  • 44
  • 74
  • Set delegate self. error shows you the whole line of incorrect code. you can write the code above (uialertview implementation)in one line – 0xDE4E15B Jan 29 '11 at 22:57

2 Answers2

0

Why have you not set the delegate to self?

How do you know the line stops at otherButtonTitles:nil? If there is a crash log, post the results of it.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
0

You must set delegate a value, because it needs to call dissWith, delegate method of the alertView. So please set:

delegate: self
Taryn
  • 242,637
  • 56
  • 362
  • 405
Waqas Raja
  • 10,802
  • 4
  • 33
  • 38
  • It's iPhone so, expect the unexpected, Build -> Clean then Build -> Clean All targets then check if Why it's not working on where currently working so, so simple set delegate other than nil – Waqas Raja Jan 29 '11 at 23:12