Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将文本字段添加到警报视图?Xcode 4.5 iOS6_Ios_Xcode_Alertview - Fatal编程技术网

如何将文本字段添加到警报视图?Xcode 4.5 iOS6

如何将文本字段添加到警报视图?Xcode 4.5 iOS6,ios,xcode,alertview,Ios,Xcode,Alertview,如何将文本字段添加到alertview?我正在尝试做一个应用程序,在应用程序提交编辑之前,用户必须首先通过在所述alertview上键入其密码进行身份验证,但我如何才能做到这一点?看来我搜索的代码已经不起作用了。这是: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In" message:@"Please enter your Password" delegate:self cancelButtonTitle:@"

如何将文本字段添加到alertview?我正在尝试做一个应用程序,在应用程序提交编辑之前,用户必须首先通过在所述alertview上键入其密码进行身份验证,但我如何才能做到这一点?看来我搜索的代码已经不起作用了。这是:

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In" message:@"Please enter your Password" delegate:self cancelButtonTitle:@"Log In" otherButtonTitles:@"Cancel", nil];
    [alert addTextFieldWithValue:@"" label:@"Password"];
    UITextField *tf = [alert textFieldAtIndex:0];
    tf.clearButtonMode = UITextFieldViewModeWhileEditing;
    tf.keyboardType = UIKeyboardTypeAlphabet;
    tf.keyboardAppearance = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
    tf.autocapitalizationType = UITextAutocorrectionTypeNo;
错误说

 "No visible @interface for 'UIAlertView' 
 declares the selector 'addTextFieldWithValue:label:'" 
 on the [alert addTextFieldWithValue:@"" label:@"Password"];
我还想问一下如何在alertview上的确认按钮上添加代码

alert.alertViewStyle = UIAlertViewStylePlainTextInput;
或者,如果您需要它来确保密码的安全性

alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
编辑:

我不是100%确定您在确认按钮上添加代码是什么意思,但是如果您想知道他们是按确认还是取消,您只需要实现

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //check the button index and do something if it's the right one.
}
或者,如果您需要它来确保密码的安全性

alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
编辑:

我不是100%确定您在确认按钮上添加代码是什么意思,但是如果您想知道他们是按确认还是取消,您只需要实现

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //check the button index and do something if it's the right one.
}

将文本字段添加到警报视图中:

    let pincodeAlert:UIAlertController = UIAlertController(title: "Hello", message: "Enter a new passcode", preferredStyle: UIAlertControllerStyle.Alert)
           pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField:UITextField!) -> Void in
            pinCodeTextField.placeholder = "password"
            pinCodeTextField.secureTextEntry = true
           })
    //Add the textField       
    pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField2:UITextField!) -> Void in
            pinCodeTextField2.placeholder = "Confirm password"
            pinCodeTextField2.secureTextEntry = true
           })

    pincodeAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
                //check entered passcodes
                }))
                pincodeAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
                presentViewController(pincodeAlert, animated: true, completion: nil)
要检查复选框中的数据,只需将其添加到OK操作处理程序中:

let passcodeEntered:String = (pincodeAlert.textFields?.first as UITextField).text

将文本字段添加到警报视图中:

    let pincodeAlert:UIAlertController = UIAlertController(title: "Hello", message: "Enter a new passcode", preferredStyle: UIAlertControllerStyle.Alert)
           pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField:UITextField!) -> Void in
            pinCodeTextField.placeholder = "password"
            pinCodeTextField.secureTextEntry = true
           })
    //Add the textField       
    pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField2:UITextField!) -> Void in
            pinCodeTextField2.placeholder = "Confirm password"
            pinCodeTextField2.secureTextEntry = true
           })

    pincodeAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
                //check entered passcodes
                }))
                pincodeAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
                presentViewController(pincodeAlert, animated: true, completion: nil)
要检查复选框中的数据,只需将其添加到OK操作处理程序中:

let passcodeEntered:String = (pincodeAlert.textFields?.first as UITextField).text

没有这样的事情:我们所有人在某个时候都是新的。祝你的应用程序好运!没有这样的事情:我们所有人在某个时候都是新的。祝你的应用程序好运!