Iphone 观察问题

Iphone 观察问题,iphone,Iphone,我正试图对警报中按下的任何按钮采取行动。我有下面的代码,第一个警报弹出,但它永远不会到达第二个 我已经对其进行了设置,以便在标头中也定义UIAlertViewProtocol -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { if(buttonIndex != [actionSheet cancelButtonIndex]) {

我正试图对警报中按下的任何按钮采取行动。我有下面的代码,第一个警报弹出,但它永远不会到达第二个

我已经对其进行了设置,以便在标头中也定义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];    
    }

}

最简单的解释是委托设置不正确。将调试器设置为
if(buttonIndex==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];    
    }

}