lln
lln

Reputation: 1

UIAlertView Question

I am trying to act upon whichever button is pressed on an alert. I have the following code and the first alert pop's up but it never gets to the second one.

I have set it up so that the UIAlertViewProtocol is defined in the header too.

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

}

Upvotes: 0

Views: 458

Answers (2)

btmanikandan
btmanikandan

Reputation: 1931

I have modified your code check it

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

}

Upvotes: 0

TechZen
TechZen

Reputation: 64428

The simplest explanation is that the delegate is not set properly. Set the debugger to if(buttonIndex ==0) to make sure the delegate method is being called. Alternatively, the button index might not be zero so the second alert is never created. The debugger can check that as well.

You should move the line...

[alert release];

... to the first method.

I've never tried to daisy chain alerts like this. It's theoretically possible that since alerts are modal and attached to the window and not the top view, that you can't add a second alert until the first one has been completely removed from the window. If the window merely releases the alert it might persist in a property of the window if the originating object has not yet released it. Having the view retained until after the second view is shown might cause a collision of some sort in the window object.

Upvotes: 1

Related Questions