标签: uialertcontroller

访问UIAlertControllers textField

我想,我在处理程序操作中访问UIAlertController的textField时遇到了麻烦.我已经用Google搜索了错误,但没有从中得到太多.我正在使用Swift和Xcode 6.0.1.这是错误:

'[AnyObject]?' does not have a member named 'subscript'

@IBAction func addPressed(sender: UIBarButtonItem) {
    var alert = UIAlertController(title: "New Event", message: "Name of the event?", preferredStyle: .ActionSheet)
    alert.addTextFieldWithConfigurationHandler(){
        textField in
        textField.placeholder = "Christmas"
        textField.becomeFirstResponder()
    }
    alert.addAction(UIAlertAction(title: "Save", style: .Default, handler: {
        action in
        var text = alert.textFields[0].text // <-- cant access alert? The exclamation mark appears here
    }))

}
Run Code Online (Sandbox Code Playgroud)

使用((alert.textFields[0] as UITextField).text)给了我完全相同的错误.

xcode ios swift uialertcontroller

3
推荐指数
1
解决办法
1473
查看次数

如何在UIAlertController中获取textField的值?

我正在尝试从UIAlertController获取textField值,但每当我尝试输入值并尝试将其打印出来时,输出都不会显示任何内容.

码:

var alert = UIAlertController(title: "Enter the password", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
alert.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
                textField.placeholder = "Enter text:"
                textField.secureTextEntry = true
                println(textField.text)

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

ios swift uialertcontroller

3
推荐指数
1
解决办法
2946
查看次数

在iOS中创建这样的自定义对话框?

在此输入图像描述

我正在尝试创建一个这样的对话框,但在每次尝试都失败了.此框覆盖其余内容,有两个textField和一个选择框.有人能帮助我吗?我用动态编程来创建对话框?或者我使用新的ViewController并通过代码调用它?我从哪里开始?

customdialog ios uialertcontroller swift2

3
推荐指数
1
解决办法
6278
查看次数

从UICollectionViewCell呈现AlertView

我的UICollectionViewCell.swift中有一个按钮:我希望,根据某些参数,它能够呈现警报.

class CollectionViewCell: UICollectionViewCell {
     var collectionView: CollectionView!

 @IBAction func buttonPressed(sender: UIButton) {

    doThisOrThat()
}


func doThisOrThat() {
    if x == .NotDetermined {
        y.doSomething()
    } else if x == .Denied || x == .Restricted {
            showAlert("Error", theMessage: "there's an error here")
            return
        }
    }

func showAlert(title: String, theMessage: String) {
    let alert = UIAlertController(title: title, message: theMessage, preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
    self.collectionView!.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

self.collectionView!.presentViewController行我拿到一个破发:

fatal error: unexpectedly found nil while …

uibutton ios uicollectionview uicollectionviewcell uialertcontroller

3
推荐指数
1
解决办法
2794
查看次数

当警报被解除时,如何弹出RootViewController?

@IBAction func addButton(sender: AnyObject) {

    let alert = UIAlertController(title: "New Exercise Added", message: "\(name)", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Ok!!", style: UIAlertActionStyle.Default, handler: nil))

    self.presentViewController(alert, animated: true, completion: nil)

    self.navigationController?.popToRootViewControllerAnimated(true)
    self.dismissViewControllerAnimated(true, completion: {})
    }
Run Code Online (Sandbox Code Playgroud)

在按钮的IB动作功能中,我有一个警报,然后是一些代码,以更改为不同的ViewController.

在警报后到达这些代码行时程序崩溃:

2016-01-04 17:48:27.147 FitnessApp [60584:4080964] popToViewController:transition:在发生现有转换或演示时调用; 导航堆栈不会更新.

转换完成后如何运行代码来更改ViewController?

ios swift uialertcontroller

3
推荐指数
1
解决办法
5259
查看次数

UIAlertViewController:取消和其他操作按钮的独立色调颜色

是否可以为取消和其他操作按钮提供单独的色调颜色?目前我正在改变色调颜色controller.view.tintColor = [UIColor blackColor];

但它也改变了取消按钮的色调颜色.我需要设置不同的色调颜色,说红色到取消按钮.请帮帮我们.

objective-c ios uialertcontroller

3
推荐指数
1
解决办法
1633
查看次数

警告:不建议在分离的视图控制器上显示视图控制器

我的情况与我在这里找到的所有其他例子不同.我有一个基于标签的应用程序.在其中一个选项卡上,用户可以按下一个按钮,该按钮可以同时从Web服务器下载多个文件.

我使用NSOperation来执行每个下载,以便我可以利用内置的依赖项.下载都发生在后台线程上,因此应用程序保持响应.最后的下载完成后,我在屏幕上放置了一个alertController,让用户知道它们已经完成.

如果用户在显示警报控制器时选择了不同的选项卡,则会收到警告:"不建议在分离的视图控制器上显示视图控制器"

如果它们仍然在开始下载的相同选项卡上,那么我不会收到警告.我试过更换:

[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

[self.view.window.rootViewController presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

但结果是从不出现alertController.

我在主线程上呈现alertController.

我无法预测下载完成时用户将使用哪个选项卡视图控制器,并且真的想要摆脱此警告.

我正在使用Obj-C开发macOS和Xcode 8.

xcode objective-c compiler-warnings ios uialertcontroller

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

我无法在Swift 3中的响应中使用Alert

嗨,我正在使用post and get响应方法,它工作良好,但是有两个问题:1-当响应为get时,我无法使用警报; 2-在另一个变化的响应中,我无法获得api_token和Id

这是我用于发布的代码**我使用的是本地代码,但是您可以更改网址并对此进行测试**

 var request = URLRequest(url: URL(string: "http://172.16.15.137:8888/TheoryTipo/public/api/register")!)
                     request.httpMethod = "POST"
                     let postString = "name=\(usernameforsignup.text!)&email=\(emailforsignup.text!)&password=\(passwordforsignup.text!)&tel=\(phonenumberforsignup.text!)"

                    print(postString)

                     request.httpBody = postString.data(using: .utf8)
                     let task = URLSession.shared.dataTask(with: request) { data, response, error in
                     guard let data = data, error == nil else {
                        // check for fundamental networking error
                     print("error=\(error)")

                        let alertController = UIAlertController(title: "Error", message: "can't Connect to the server", preferredStyle: UIAlertControllerStyle.alert)

                        let okAction = UIAlertAction(title: "retry", style: UIAlertActionStyle.default)
                        {
                            (result : UIAlertAction) -> Void in
                        }
                        alertController.addAction(okAction)
                        self.present(alertController, …
Run Code Online (Sandbox Code Playgroud)

http-post ios uialertcontroller swift3

3
推荐指数
1
解决办法
975
查看次数

初始化UIAlertController的子类

我希望创建一个自定义子类UIAlertController。如果我理解正确,则需要super.init(title...在子类初始化期间调用某处。

但是我一直遇到指定初始化程序的问题。我已经阅读了文档,无法弄清楚如何使其工作。这是我的代码(请注意代码中的注释):

class AccountInfoActionSheet: UIAlertController {

    required init?(coder aDecoder: NSCoder) { //xcode says I need this
        super.init(coder: aDecoder) //it also says I need to call a designated initializers so here it is
        super.init(title: "Info", message: "Heres the Info", preferredStyle: .actionSheet) //but now I can't call this initializer
        fatalError("init(coder:) has not been implemented")
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:由于UIAlertController不能被子类化,我只是创建了一个函数,该函数返回UIAlertController需要在ViewController内部正确配置的函数。

initialization subclass swift uialertcontroller

3
推荐指数
1
解决办法
1317
查看次数

在Objective-C的UIAlertController下添加Textview

如何在UIAlertController?下添加文本视图?我尝试了下面的方法,但是textview不能正确显示。

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Comments" message:@"Enter your submit comments" preferredStyle:UIAlertControllerStyleAlert];
alertController.view.autoresizesSubviews = YES;

UITextView * alertTextView = [[UITextView alloc] initWithFrame:CGRectZero];
alertTextView.translatesAutoresizingMaskIntoConstraints = NO;
alertTextView.backgroundColor = [UIColor greenColor];

NSLayoutConstraint *leadConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:alertTextView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:-8.0];
NSLayoutConstraint *trailConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:alertTextView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:8.0];

NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:alertTextView attribute:NSLayoutAttributeTop multiplier:1.0 constant:-64.0];
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:alertController.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:alertTextView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:64.0];
[alertController.view addSubview:alertTextView];
[NSLayoutConstraint activateConstraints:@[leadConstraint, trailConstraint, topConstraint, …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextview ios uialertcontroller

3
推荐指数
1
解决办法
1311
查看次数