0

嗨,在我的视图控制器中,有两个带有多个按钮的警报视图,这些按钮将触发另一种方法。所以我使用以下代码,但

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

这个方法根本没有调用。这是我使用的全部代码

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section==1)
    {
        if(indexPath.row==0)
        {
            GMMAboutUsViewController *aboutus=  [self.storyboard instantiateViewControllerWithIdentifier:@"aboutus"];
            [self.navigationController pushViewController:aboutus animated:YES];
        }
        else if (indexPath.row==1)
        {
            GMMTermsOfServiceViewController *termsofservice=  [self.storyboard instantiateViewControllerWithIdentifier:@"termsofservice"];
            [self.navigationController pushViewController:termsofservice animated:YES];
        }
        else if (indexPath.row==2)
        {
            GMMUserGuideViewController *userguide=  [self.storyboard instantiateViewControllerWithIdentifier:@"userguide"];
            [self.navigationController pushViewController:userguide animated:YES];

        }
        else
        {
            GMMCreditsandCopyrightsViewController *creditsandcopyrights=  [self.storyboard instantiateViewControllerWithIdentifier:@"creditsandcopyrights"];
            [self.navigationController pushViewController:creditsandcopyrights animated:YES];

        }
    }
    else 
    {
        if(indexPath.row==0)
        {
           alertDeregister=[[UIAlertView alloc]
                                      initWithTitle:@"Deregister"
                                      message:@"Are you sure you want to Deregister ? "
                                      delegate:nil
                                      cancelButtonTitle:@"NO"
                                      otherButtonTitles:nil, nil];
            alertDeregister.tag=kFirstAlertViewTag;
            [alertDeregister addButtonWithTitle:@"YES"];
            [alertDeregister show];

        }
        else 
        {
            alertLogout=[[UIAlertView alloc]
                                      initWithTitle:@"Logout"
                                      message:@"Are you sure you want to logout ? "
                                      delegate:nil
                                      cancelButtonTitle:@"cancel"
                                      otherButtonTitles:nil, nil];
            alertLogout.tag=kSecondAlertViewTag;
            [alertLogout addButtonWithTitle:@"Logout"];
            [alertLogout show];

        }

    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if(alertView==alertDeregister)
    {
        if(buttonIndex==0)
        {
            [self deregister];
        }

    }
    else if (alertView==alertLogout)
    {
        if(buttonIndex==0)
        {
            GMMLoginController *login = [self.storyboard instantiateViewControllerWithIdentifier:@"l"];
            [self presentModalViewController:login animated:NO];
        }
    }

}
4

2 回答 2

1

您应该将 self 作为委托传递。

    alertLogout=[[UIAlertView alloc]
                              initWithTitle:@"Logout"
                              message:@"Are you sure you want to logout ? "
                              delegate:self
                              cancelButtonTitle:@"cancel"
                              otherButtonTitles:nil, nil];
于 2013-04-10T04:02:24.000 回答
1

您不必添加到 .h 文件中,只需在创建警报视图时添加 delegate:self 即可调用 clickedButtonAtindex 方法。请加

    NSLog("clickedButtonAtIndex called");

到您的 clickedButtonAtIndex 方法以检查其调用是否存在问题

于 2013-04-11T19:47:05.887 回答