热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在iPad,iOS8和Objective-C中,UIAlertController没有显示取消按钮

如何解决《在iPad,iOS8和Objective-C中,UIAlertController没有显示取消按钮》经验,为你挑选了1个好方法。

我正在尝试使用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];

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



1> 小智..:

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


另外,如果您仍然想显示一个,只需将取消动作的`style:`更改为`UIAlertActionStyleDefault`
推荐阅读
author-avatar
城哥_1986
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有