gpt4 book ai didi

ios - 单击特定按钮时显示多个警报 Controller ?

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

我有一个标签,它提出了一个问题,用户需要通过点击“YES”或“NO”按钮来回答。如果用户直接点击 NEXT 按钮,警告会弹出,说 Choose Yes or No 如果用户选择 Yes,那么他会在那里自己得到一个新的子问题,如果用户点击 NEXT 而没有回答子问题,另一个 alertView 应该弹出窗口。在这两种情况下,只显示一个警报 View 。请帮忙这是代码

 -(IBAction)btnNextClicked:(id)sender {

activeButton = sender;
if (([_txtOwnerShipPercentage.text isEqualToString:@" "] || _txtOwnerShipPercentage.text==nil || _txtOwnerShipPercentage.text.length==0) && (activeButton.tag == 1)) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Select Ownership Percentage" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
} else if (activeButton.tag == 0){
UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Select 'YES' or 'No'" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController2 addAction:okAction];
[self presentViewController:alertController2 animated:YES completion:nil];

}
}

并且我已分别将标签设置为 YES 和 No Button... 1 & 2。activebutton 只不过是全局声明的 UIButton

最佳答案

这里是您如何根据您的要求在一个上下文中管理两个或多个警报 Controller 的代码。

    //declare first alert controller
UIAlertController *alertviewcontroller1 = [UIAlertController alertControllerWithTitle:@"My Alert 1"
message:@"This is an action sheet of alert 1"
preferredStyle:UIAlertControllerStyleActionSheet];

//declare second alert controller
UIAlertController *alertviewcontroller2 = [UIAlertController alertControllerWithTitle:@"My Alert 2"
message:@"This is an action sheet of alert 2"
preferredStyle:UIAlertControllerStyleActionSheet];

//declare first alert controller action with hendler
UIAlertAction *firstActionOfAlert1 = [UIAlertAction actionWithTitle:@"YES"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

//Present second alert controller when user taps on 'YES' of first alert controller.
[self presentViewController:alertviewcontroller2 animated:YES completion:nil];
}];

//declare second alert controller action with hendler
UIAlertAction *firstActionOfAlert2 = [UIAlertAction actionWithTitle:@"YES"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {


}];

//add both actions relatively
[alertviewcontroller1 addAction:firstActionOfAlert1];
[alertviewcontroller1 addAction:firstActionOfAlert2];

//Present first alert controller
[self presentViewController:alertviewcontroller1 animated:YES completion:nil];

关于ios - 单击特定按钮时显示多个警报 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671849/

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