标签: uialertcontroller

UIAlertController在外部点击时处理解除(IPad)

在iOS8之前,我们使用UIActionSheet来显示警报,现在我们需要使用UIAlertController.

当我们使用UIActionSheet时,我们可以通过将clickedButtonAtIndex与cancelButtonIndex进行比较来轻松处理用户在弹出窗口外点击的情况(这意味着他想要取消操作) - 如果用户确实在弹出窗口外按下了取消按钮索引在这个功能.

我们如何使用新的UIAlertController处理这些情况?我试图使用"完成"块,但它没有任何上下文.有一个简单的方法来处理这个?(除了"保存"某些一般变量中的动作状态).

uiactionsheet ipad ios ios8 uialertcontroller

27
推荐指数
2
解决办法
2万
查看次数

有没有办法在Swift中将UIPickerView添加到UIAlertController(Alert或ActionSheet)中?

我对swift(以及iOS编程)完全不熟悉,但我开始搞乱它(当一切仍然是beta版本时,这不是一个好主意:D).所以我试着自己弄清楚,但仍然没有.甚至试图添加包含选择器的子视图而没有任何成功.那么任何人都可以帮助我吗?

uipickerview ios swift uialertcontroller

25
推荐指数
4
解决办法
5万
查看次数

如何在iOS9中更改UIAlertController按钮文本颜色?

问题类似于iOS 8 UIActivityViewController和UIAlertController按钮文本颜色使用窗口的tintColor但在iOS 9中.

我有一个UIAlertController,即使我试图设置,解除按钮也会保持白色

[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor blackColor]];

UIAlertController *strongController = [UIAlertController alertControllerWithTitle:title
                                                             message:message
                                                      preferredStyle:preferredStyle];
strongController.view.tintColor = [UIColor black];
Run Code Online (Sandbox Code Playgroud)

objective-c ios uialertcontroller

25
推荐指数
7
解决办法
3万
查看次数

从UIView/NSObject类显示UIAlertController

我有,working iOS application 为了support iOS8,我正在取代UIAlertView/UIActionSheet with UIAlertController.

问题:
为了显示UIAlertController,我需要UIViewController类的presentViewController方法.
但是 UIAlertView中是从哪个是类显示器inheritedUIView or NSObject,
我不能[self presentViewController...]为明显的原因的方法.

我的工作:
我尝试获取rootViewController表单当前窗口并显示UIAlertController.

[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController ...]
Run Code Online (Sandbox Code Playgroud)

但有一些旋转问题,如果我的当前视图控制器没有旋转支持,它将旋转,如果UIAlertController打开.

问题:
有没有人遇到同样的问题并且有安全的解决方案?
如果是,请给我一些例子或给一些指导

objective-c uialertview uiactionsheet ios8 uialertcontroller

24
推荐指数
5
解决办法
3万
查看次数

在Swift中的AppDelegate中显示警报

我尝试下一个代码片段:

var alert = UIAlertController(title: "Alert", message: "Cannot connect to : \(error!.localizedDescription)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中,但它在控制台中打印出下一个错误:

Warning: Attempt to present <UIAlertController: 0x7ff6cd827a30> on <Messenger.WelcomeController: 0x7ff6cb51c940> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

ios swift uialertcontroller

24
推荐指数
6
解决办法
3万
查看次数

在iOS8中更改操作表弹出箭头

我正在使用UIAlertController.但是在iOS 8的iPad上,actionSheet显示了弹出式箭头.任何隐藏箭头的想法?

这是我的代码:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"this is alert controller" message:@"yeah" preferredStyle:UIAlertControllerStyleActionSheet];

            UIAlertAction *cancelAction = [UIAlertAction
                                           actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                                           style:UIAlertActionStyleCancel
                                           handler:^(UIAlertAction *action)
                                           {
                                               NSLog(@"Cancel action");
                                           }];

            UIAlertAction *okAction = [UIAlertAction
                                       actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction *action)
                                       {
                                           NSLog(@"OK action");
                                       }];

            UIAlertAction *deleteAction = [UIAlertAction
                                           actionWithTitle:NSLocalizedString(@"Delete", @"Delete action")
                                           style:UIAlertActionStyleDestructive
                                           handler:^(UIAlertAction *action) {
                                               NSLog(@"Delete action");
                                           }];

            [alertController addAction:cancelAction];
            [alertController addAction:okAction];
            [alertController addAction:deleteAction];

            UIPopoverPresentationController *popover = alertController.popoverPresentationController;
            if (popover) {
                popover.sourceView = self.view;
                popover.sourceRect = self.view.bounds;
                popover.permittedArrowDirections = UIPopoverArrowDirectionUnknown;
            } …
Run Code Online (Sandbox Code Playgroud)

uiactionsheet ipad uipopovercontroller ios8 uialertcontroller

21
推荐指数
3
解决办法
2万
查看次数

如何在UIAlertController的中心显示活动指示器?

我目前UIAlertController正在屏幕上显示.警报视图应仅显示2个元素,标题和UIActivityIndicatorView警报中心.以下是显示警报及其元素的功能.

func displaySignUpPendingAlert() -> UIAlertController {
        //Create the UIAlertController
        let pending = UIAlertController(title: "Creating New User", message: nil, preferredStyle: .Alert)
        //Create the activity indicator to display in it.
        let indicator = UIActivityIndicatorView(frame: CGRectMake(pending.view.frame.width / 2.0, pending.view.frame.height / 2.0, 20.0, 20.0))
        indicator.center = CGPointMake(pending.view.frame.width / 2.0, pending.view.frame.height / 2.0)
        //Add the activity indicator to the alert's view
        pending.view.addSubview(indicator)
        //Start animating
        indicator.startAnimating()

        self.presentViewController(pending, animated: true, completion: nil)
        return pending
    }
Run Code Online (Sandbox Code Playgroud)

但是,活动指示器不会显示在视图的中心,实际上它显示在屏幕的右下方,远离视图.这是什么原因?

编辑:我知道我可以硬编码指标位置的数字,但我希望警报可以在多个屏幕尺寸和方向的多个设备上工作.

uiview uiactivityindicatorview ios swift uialertcontroller

21
推荐指数
5
解决办法
3万
查看次数

21
推荐指数
2
解决办法
3万
查看次数

警告:尝试在<...>上呈现<UIAlertController:0x7facd3946920>已经呈现(null)

我有一个长按手势一组UITableView呈现一个UIAlertController包含单元格的文本.当UIAlertController提出时,我得到这个警告:

Attempt to present <UIAlertController: 0x7fd57384e8e0>  on <TaskAppV2.MainTaskView: 0x7fd571701150> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)

根据我的理解,MainTaskView(UITableView)已经呈现了一个视图,因此它不应该呈现第二个视图,UIAlertController.所以我从类似的问题尝试了这个解决方案.它不起作用,因为我收到相同的警告.我该怎么做才能解决这个警告?请参阅下面的代码:

func longPressedView(gestureRecognizer: UIGestureRecognizer){

    /*Get cell info from where user tapped*/
    if (gestureRecognizer.state == UIGestureRecognizerState.Ended) {
        var tapLocation: CGPoint = gestureRecognizer.locationInView(self.tableView)

        var tappedIndexPath: NSIndexPath? = self.tableView.indexPathForRowAtPoint(tapLocation)
        if (tappedIndexPath != nil) {
            var tappedCell: UITableViewCell? = self.tableView.cellForRowAtIndexPath(tappedIndexPath!)
            println("the cell task name is \(tappedCell!.textLabel!.text!)")
        } else {
            println("You didn't tap on a cell")
        }
    }

    /*Long …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uialertcontroller

21
推荐指数
2
解决办法
1万
查看次数

iOS应用在后台时显示提醒

当我的iOS应用程序在后台时(我正在使用位置),我想显示警报视图.

例如,即使在以下情况下,优步合作伙伴(驱动程序)应用程序也会显示警报并播放声音:

  • 我关掉了通知!
  • 我的iPhone处于静音模式!

我知道本地通知方法,如果用户关闭/更改设置中的通知,它不起作用.我正在寻找不同的东西.

在此输入图像描述
为达到上述状态而执行的操作:

  • 在Uber Partner App上线(你是司机!)
  • 在"设置"中禁用应用程序的通知
  • 将应用程序移至后台并等待Ride请求
  • 一段时间后,乘车请求会弹出一个警报视图,并在后台播放声音

当然,即使用户在"设置"中禁用"通知" ,应用程序也可以使用API 轻触静默远程通知didReceiveRemoteNotification: fetchCompletionHandler:.但是,警报是如何弹出的,这就是我想要找到的.

ios springboard uialertcontroller

20
推荐指数
3
解决办法
3634
查看次数