iPad、iOS8 和 Objective-C 中的 UIAlertController 不显示“取消”按钮

2024-04-01

我正在尝试使用 UIAlertController。我需要一个带有两个按钮的弹出窗口——“取消”和“删除并注销”。但我只能看到“删除并退出”按钮,看不到取消按钮。这是代码:-

NSString *confirmText = "Hi";   
UIAlertController *alert = [UIAlertController alertControllerWithTitle:confirmText message:@"" preferredStyle:UIAlertControllerStyleActionSheet];


// Created a deleted action
UIAlertAction *destroyAction = [UIAlertAction actionWithTitle:@"Delete and Sign Out"
                                         style:UIAlertActionStyleDestructive
                                       handler:^(UIAlertAction *action) {
                                           NSLog(@"Delete Action Pressed");
                                           [self signout];
                                       }];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                       style:UIAlertActionStyleCancel
                                                     handler:nil];


[alert.view setTintColor:[UIColor grayColor]];
[alert addAction:cancelAction];
[alert addAction:destroyAction];
[alert setModalPresentationStyle:UIModalPresentationPopover];

UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
// Set the sourceView.
popPresenter.sourceView = logoutButton;
popPresenter.sourceRect = logoutButton.bounds;
[self presentViewController:alert animated:YES completion:nil];

不幸的是,我无法发布图片,所以如果您需要更多说明,请告诉我。


在 iOS8 上,取消按钮仅在需要时显示。如果您在 iPhone 上运行该应用程序,它是可见的。如果您在 iPad 上运行该应用程序,则不会显示取消按钮,并且当用户点击弹出窗口外部时,将调用取消操作的处理程序 (style:UIAlertActionStyleCancel)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iPad、iOS8 和 Objective-C 中的 UIAlertController 不显示“取消”按钮 的相关文章

随机推荐