标签: uialertcontroller

在iPhone上的popover中呈现UIAlertController ActionSheet

我正在创建和呈现ActionSheet如下:

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
alertController.modalPresentationStyle = .Popover

// Add some buttons

alertController.popoverPresentationController?.delegate = self
alertController.popoverPresentationController?.barButtonItem = someBarButton

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

这工作正常在iPad上,不过alertController.popoverPresentationControllernil在iPhone上.

我已经成功地使用自适应segue样式在iPhone上使用自适应segue样式呈现弹出窗口并实现adaptivePresentationStyleForPresentationController委托方法以返回正确的UIModalPresentationStyle但是我已经卡住了如何在代码中执行它,UIAlertController因为它popoverPresentationController在iPhone 上没有

iphone popover ios uialertcontroller

14
推荐指数
1
解决办法
6642
查看次数

当UIAlertcontroller在Swift中出现时,KEEP键盘是否打开?

弹出警报时,键盘将被解除.我到处寻找,但没有找到保持键盘可见的解决方案.当提示警报时,文本字段似乎会自动重新响应第一响应者,因为警报是以模态方式呈现的.如何将键盘保持在此警报之后,即使没有可能的交互,文本字段仍然可以编辑?

keyboard ios presentviewcontroller swift uialertcontroller

14
推荐指数
1
解决办法
5104
查看次数

Swift尝试显示其视图不在窗口层次结构中的UIAlertController(在TWTRShareEmailViewController之后显示)

我在我的应用程序的注册过程中使用Twitter登录.而且我要求用户的电子邮件.一旦我得到它,我想呈现一个UIAlertController.

这是我的代码:

func askForTWMail(){
    if (Twitter.sharedInstance().session() != nil) {
        let shareMailVC=TWTRShareEmailViewController(completion: {(mail:String!, error:NSError!) in
            if (mail != nil) {
                print("GOT MAIL: \(mail)")
                self.gotMail()
            }else{
                print("MAIL VC ERROR: \(error)")
            }
        })
        println("PRESENT MAIL VC")
        self.presentViewController(shareMailVC, animated: true, completion: nil)
    }else{
        println("User not logged in")
    }
}

func gotMail(){
    var alertController=UIAlertController(title: "Some title", message: "Some message", preferredStyle: UIAlertControllerStyle.Alert)
    var okAction=UIAlertAction(title:"Yes", style: UIAlertActionStyle.Default) {
    UIAlertAction in
    //some action
    }
    var cancelAction=UIAlertAction(title:"No", style: UIAlertActionStyle.Cancel){
    UIAlertAction in
    //some action
    }
    alertController.addAction(okAction)
    alertController.addAction(cancelAction)
    self.presentViewController(alertController, animated: true, …
Run Code Online (Sandbox Code Playgroud)

email twitter ios swift uialertcontroller

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

将图像添加到警报视图

当用户按下添加按钮时,我会弹出一个警报视图.如何将图像添加到警报视图?

我添加了一些我从堆栈溢出引用的代码.我的保存按钮被替换为图像,图像显示为蓝色...

警报视图代码

var alert = UIAlertController(title: "Spring Element \(springNumber)",
            message: "Add spring properties",
            preferredStyle: .Alert)

        let saveAction = UIAlertAction(title: "Save",
            style: .Default) { (action: UIAlertAction!) -> Void in

                let textField1 = alert.textFields![0] as UITextField
                self.txtField1.append(textField1.text)
                self.tableView.reloadData()

                let textField2 = alert.textFields![1] as UITextField
                self.txtField2.append(textField2.text)
                self.tableView.reloadData()

                println(self.txtField1)
                println(self.txtField2)
        }

        let cancelAction = UIAlertAction(title: "Cancel",
            style: .Default) { (action: UIAlertAction!) -> Void in
        }

        //adding textfield1
        alert.addTextFieldWithConfigurationHandler {
            (textField1: UITextField!) -> Void in
            textField1.placeholder = "Force"
        }

        //adding textfield2
        alert.addTextFieldWithConfigurationHandler {
            (textField2: …
Run Code Online (Sandbox Code Playgroud)

uiimage uialertview ios swift uialertcontroller

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

如何在警报控制器的文本字段中设置数字键盘[swift]

我正在尝试调用具有文本字段的警报控制器.但我想立即显示数字键盘,因为用户只应输入数字.我尝试了以下但它不起作用.

let alert = UIAlertController(title: "New Rating", message: "Rate this!", preferredStyle: UIAlertControllerStyle.Alert)

  let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in })

  let saveAction = UIAlertAction(title: "Save", style: .Default, handler: { (action: UIAlertAction!) in

    let textField = alert.textFields![0] as UITextField
    textField.keyboardType = UIKeyboardType.NumberPad

    self.updateRating(textField.text)
  })

  alert.addTextFieldWithConfigurationHandler { (textField: UITextField!) in }

  alert.addAction(cancelAction)
  alert.addAction(saveAction)

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

uitextfield ios swift uialertcontroller

13
推荐指数
2
解决办法
6869
查看次数

未调用UIAlertAction完成块 - iOS

当用户点击按钮时,我的应用程序中会显示一个带有UIAlertController的iOS应用程序.

这一切都很好,除了一件事,完成块不会因某种原因被调用.

这是我的代码:

// Setup the alert information/type.
UIAlertController *action_view = [UIAlertController alertControllerWithTitle:@"Test title" message:@"test message" preferredStyle:UIAlertControllerStyleActionSheet];

// Create and add the cancel button.
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {

    [action_view dismissViewControllerAnimated:YES completion:^{
        NSLog(@"asdhfgjk");
    }];
}];

// Add the action button to the alert.
[action_view addAction:cancel];

// Present the alert to the user.
[self presentViewController:action_view animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

如果您运行该代码,您将看到解除控制器不会运行的行,并且NSLog它内部的语句也不会.但是,如果你删除NSLog并将完成块设置为nil,那么它确实运行....为什么???

谢谢你的时间,丹.

cocoa-touch objective-c uiactionsheet ios uialertcontroller

13
推荐指数
1
解决办法
7650
查看次数

如何使用UITableView自定义UIAlertController,或者在Pages应用程序中是否有像此UI一样的默认控件?

我想实现UIAlertViewController这样的(参考:Pages和Keynote应用程序):

在此输入图像描述.

我已经实现了一个自定义的tableview,并通过模仿来呈现视图UIAlertViewController.但我无法实现与上面类似的用户界面.有没有可用的默认控制器?

-(void)share:(id)sender
{
    [self setModalPresentationStyle:UIModalPresentationCurrentContext];

    AlertViewController *renameCntrl = [self.storyboard instantiateViewControllerWithIdentifier:AlertTblViewidentifier];
    renameCntrl.optionViewDelegate = self;
    renameCntrl.providesPresentationContextTransitionStyle = YES;
    renameCntrl.definesPresentationContext = YES;
    [renameCntrl setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    [self presentViewController:renameCntrl animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

uitableview uiactionsheet ios uialertcontroller

13
推荐指数
1
解决办法
4743
查看次数

使用preferredStyle:.ActionSheet更改UIAlertController中取消按钮的颜色

是否可以将取消按钮的颜色更改为红色,我知道我们可以使用破坏性样式

  let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Destructive) { action -> Void in
            print("Cancel")
        }
Run Code Online (Sandbox Code Playgroud)

但我想分开取消按钮,就像这样 在此输入图像描述

uiactionsheet swift uialertcontroller

13
推荐指数
4
解决办法
6836
查看次数

swift UIAlertController与pickerView按钮操作熬夜

我是新手,我正在尝试UIAlertContoller用,PickerView 但我有问题,巴顿斯,这里有一张照片

在此输入图像描述

当我试图改变约束时按钮保持不动我在这里读了很多答案,但我没有找到任何solotuin

这是我的代码:

func distance(){
    let editRadiusAlert = UIAlertController(title: "Choose distance", message: "", preferredStyle: UIAlertControllerStyle.alert)
    let pickeViewFrame: CGRect = CGRect(x: 0, y: 0, width: 250, height: 300)
    let pickerViewRadius: UIPickerView = UIPickerView(frame: pickeViewFrame)
    pickerViewRadius.delegate = self
    pickerViewRadius.dataSource = self
    editRadiusAlert.view.addSubview(pickerViewRadius)
    editRadiusAlert.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.default,handler:nil))
    editRadiusAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
    editRadiusAlert.view.addConstraint(NSLayoutConstraint(item: editRadiusAlert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.5))
    self.present(editRadiusAlert, animated: true, completion: nil)
} 
Run Code Online (Sandbox Code Playgroud)

xcode uipickerview swift uialertcontroller swift3

13
推荐指数
1
解决办法
9167
查看次数

更改UIAlertcontroller背景颜色

好吧,我有这个警告,我正在使用它,我希望它的背景是黑色而不是灰色的样子.我已设法更改标题和消息的文本颜色,但不更改背景颜色.那么我想要的颜色.我已将其更改为绿色蓝色和白色,但不是黑色.当我尝试将其更改为黑色时,它会变为灰色.任何建议都会有所帮助并受到赞赏.我试过这里如何更改UIAlertController的背景颜色?这就是我到达现在的位置.

这就是我现在要做的事情:

func showAlert(title:String, message:String) {

    //Set up for the title color
    let attributedString = NSAttributedString(string: title, attributes: [
        NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here,
        NSForegroundColorAttributeName : UIColor.whiteColor()
        ])
    //Set up for the Message Color
    let attributedString2 = NSAttributedString(string: message, attributes: [
        NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here,
        NSForegroundColorAttributeName : UIColor.whiteColor()
        ])

    let alert = UIAlertController(title: title,message: message, preferredStyle: .Alert)

    alert.setValue(attributedString, forKey: "attributedTitle")
    alert.setValue(attributedString2, forKey: "attributedMessage")
    //alert.view.tintColor = UIColor.whiteColor()
    let dismissAction = UIAlertAction(title: "Dismiss", style: .Destructive, handler: nil) …
Run Code Online (Sandbox Code Playgroud)

objective-c ios swift uialertcontroller

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