在iPad,iOS8和Objective-C中,UIAlertController没有显示取消按钮 [英] Cancel button is not showing for a UIAlertController in iPad, iOS8 and in objective-C

查看:390
本文介绍了在iPad,iOS8和Objective-C中,UIAlertController没有显示取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UIAlertController。我需要一个带有两个按钮的弹出框 - 取消和删除并退出。但我只能看到删除并退出按钮而不是取消按钮。以下是代码: -

I am trying to use UIAlertController. I need a popover with two buttons -- "Cancel" and "Delete and Sign Out". But I can only see the "Delete and Sign out" button and not the cancel button. Here is the code:-

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

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

Unfortunately, I am unable to post images, so please let me know if you need anymore clarifications.

推荐答案

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

On iOS8 the cancel button is shown only when needed. If you run the app on iPhone it is visible. If you run the app on iPad the cancel button is not shown and the handler for the cancel action (style:UIAlertActionStyleCancel) is called when the user taps outside the popup.

这篇关于在iPad,iOS8和Objective-C中,UIAlertController没有显示取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆