开发者

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 unders开发者_StackOverflow社区tand 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜