简体   繁体   中英

Can't get UIAlertView to work

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 :)

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.

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

delegate: self

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM