gpt4 book ai didi

ios - 如何在 UIVIewController 中添加多个 UIAlertview?

转载 作者:行者123 更新时间:2023-11-28 22:36:12 25 4
gpt4 key购买 nike

您好,在我的 View Controller 中有两个带有多个按钮的警报 View ,这些按钮将触发另一种方法。所以我使用以下代码,但是

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

}

最佳答案

您应该将自己作为委托(delegate)传递。

喜欢

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

关于ios - 如何在 UIVIewController 中添加多个 UIAlertview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15910512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com