开发者

Show Alert in clickedButtonAtIndex?

开发者 https://www.devze.com 2023-02-07 15:57 出处:网络
i need to show a confirm alert after the user press buttonIndex 1 but... if i use popViewcontroller in clickedButtonAtIndex it crash without errors.

i need to show a confirm alert after the user press buttonIndex 1 but... if i use popViewcontroller in clickedButtonAtIndex it crash without errors.

The problem is that

[self.navigationController popViewControllerAnimated:YES];

is called before second Alert click...

how to fix?

This is my code:

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        UIAlertView *alert = 
            [[UIAlertView alloc] initWithTitle:@"OK!"
                                    message:@"Completed"
                                    deleg开发者_运维百科ate:self 
                    cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show]; 
            [alert release];

            [self.navigationController popViewControllerAnimated:YES];
    }
}


Set the tag properties of the two UIAlertViews to 1 and 2, respectively. Then, in the delegate method, use if statements to check the tag of the UIAlertView argument.

Example:

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 1)
    {
        //check the button index
        //create and display the other alert view (set the tag property here to 2)
    }
    else if (alertView.tag == 2)
    {
        //pop the view controller
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消