1

我在让 UIAlert 返回布尔值时遇到了麻烦,而且我真的在网上找不到任何东西,所以我希望你们能帮忙。首先,这是应用程序的基本设置。基本上,当用户单击“单击”按钮时,会弹出一个警报,选择“是”和“否”。到目前为止,这是我为按钮设置的代码:

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Choose"
                                                                message:@"Answer the question" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction= [UIAlertAction actionWithTitle:@"YES"
                                                       style:UIAlertActionStyleDefault
                                                     handler:nil];
UIAlertAction *noAction= [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:defaultAction];
[alert addAction:noAction];
[self presentViewController:alert animated:YES completion:nil];

我怎样才能准确地使用完成选项来返回一个布尔值?

4

1 回答 1

0

在 UIAlertAction 本身中使用完成处理程序。例如,

  UIAlertAction *noAction= [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
                              {
                                  NSLog(@"NO");
                                  [alert dismissViewControllerAnimated:YES completion:nil];

                              }];
于 2016-01-25T05:55:12.467 回答