2011-01-29 115 views
0

我有UIAlertView的问题,我不明白。我无法让它工作。我在测试过程中更改了代码,所以按下按钮时UIAlertView应该直接点击。无法让UIAlertView正常工作

我已经测试了断点/调试器,当按下按钮时发生了什么,它停在的第一行是“otherButtonTitles:nil”;“。

我在应用程序的其他部分测试了一段代码,它工作正常。

我不知道我做错了什么。

- (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 =====================

当我复制这段代码到另一个按钮的作用?

在这里它是在一条线,测试具有相同的结果:

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]; 

==============更新#2 ======== ==========

问题解决了,即使我不明白原因,因为我在测试过程中移除了“退出(0)”,远远低于UIAlertView。

感谢大家谁回答:)

+0

设置代表自我。错误显示了整行错误的代码。你可以将上面的代码(uialertview实现)写在一行中 – 0xDE4E15B 2011-01-29 22:57:24

回答

0

你为什么不设置委托自我?

你怎么知道该线路停在otherButtonTitles:nil?如果有崩溃日志,请发布它的结果。

+0

我测试过一个断点,并且每行都有一行,所以我看到了跳跃的位置。 – PeterK 2011-01-29 22:50:02

+0

让代码遍历并查看崩溃日志的内容,或发布您的报告。 – WrightsCS 2011-01-29 22:52:53

0

您必须设置委托值,因为它需要调用dissWith,委托方法为alertView。所以请设置:

delegate: self