Pregunta

In my UIAlertView, I want to open another UIView when "OK" button is pressed.

But the problem is, even after the UIView is displayed, alert remains in screen and once it fades away, the UIView seems to be disabled.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add details" message:@" Do you like to set the details now?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert show];
[alert release];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{   // the user clicked one of the OK/Cancel buttons
    NSString *title = [alertView title];

    if([title isEqualToString:@"Add details"])
    {
        .......

Any help would be appreciated!

¿Fue útil?

Solución

Why not check for the button pressed in the delegate method instead of the title? That is, in

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0){
        // User pressed "YES"
    }else{
        // User pressed "NO"
    }
}

The cancel button has index 0 and the other buttons increase in index. In order to detect which alert was this, you should also give it a tag. Hope this helps.

Otros consejos

Could be because the new view is added before the alert view is actually dismissed. So better use the didDismissWithButtonIndex delegate to show a new view on button click event of an existing alert view, instead of clickedButtonAtIndex

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
//Add the view
}

Instead of

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Add the view
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top