簡體   English   中英

如何在UIVIewController中添加多個UIAlertview?

[英]How can i add multiple UIAlertview in a UIVIewController?

嗨,在我的視圖控制器中,有兩個帶有多個按鈕的警報視圖,這些按鈕將分解另一個方法。所以我使用以下代碼但是

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

}

你應該把自己作為代表來傳遞。

喜歡

    alertLogout=[[UIAlertView alloc]
                              initWithTitle:@"Logout"
                              message:@"Are you sure you want to logout ? "
                              delegate:self
                              cancelButtonTitle:@"cancel"
                              otherButtonTitles:nil, nil];

您不必添加到.h文件,只需添加delegate:self,在創建警報視圖時應允許調用clickedButtonAtindex方法。 請加

    NSLog("clickedButtonAtIndex called");

你的clickedButtonAtIndex方法檢查它作為問題的調用是否可能在其他地方

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM