UIAlertView问题

时间:2009-12-30 12:12:57

标签: iphone

我正在尝试按照警告上按下的任何按钮进行操作。我有以下代码和第一个警报弹出,但它永远不会到达第二个。

我已经设置好了,所以UIAlertViewProtocol也在标题中定义。

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != [actionSheet cancelButtonIndex])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something actually happened" message:@"Something was done" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"test",nil];
        [alert show];

    }

}

    -(void)alert:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex ==0)
    {
        NSLog(@"tetetete");
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [a show];
        [a release];
        [alert release];    
    }

}

2 个答案:

答案 0 :(得分:1)

最简单的解释是代理设置不正确。将调试器设置为  if(buttonIndex ==0)以确保调用委托方法。或者,按钮索引可能不为零,因此永远不会创建第二个警报。调试器也可以检查它。

你应该移动线......

  

[警告发布];

...到第一种方法。

我从未尝试像这样菊花链式警报。 理论上可能是因为警报是模态的并且附加到窗口而不是顶视图,所以在第一个警报完全从窗口中移除之前,您无法添加第二个警报。如果窗口仅释放警报,则如果原始对象尚未释放它,则它可能会持久存储在窗口的属性中。将视图保留到显示第二个视图之后可能会导致窗口对象中某种类型的冲突。

答案 1 :(得分:0)

我修改了你的代码检查

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != [actionSheet cancelButtonIndex])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something actually happened" message:@"Something was done" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"test",nil];
        [alert show];
        [alert release];

    }

}

    -(void)alert:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex ==0)
    {
        NSLog(@"tetetete");
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [a show];
        [a release];
        [a release];    
    }

}