【问题标题】:SCLAlertView - Focus on textfieldSCLAlertView - 专注于文本字段
【发布时间】:2018-02-26 20:29:56
【问题描述】:

我有一个 SCLAlertView,里面有一个文本字段。如何使该文本字段成为第一响应者,以便在显示警报视图时,我可以自动开始编写而不是先单击文本字段?

【问题讨论】:

    标签: swift uitextfield swift4


    【解决方案1】:

    显示警报后,您可以将此代码放在函数的末尾。

    @IBAction func showEdit(_ sender: AnyObject) {
        let appearance = SCLAlertView.SCLAppearance(showCloseButton: true)
        let alert = SCLAlertView(appearance: appearance)
        let txt = alert.addTextField("Enter your name")
        _ = alert.addButton("Show Name") {
            print("Text value: \(txt.text ?? "NA")")
        }
        _ = alert.showEdit(kInfoTitle, subTitle:kSubtitle)
    
        //Add this code in show function to set textfield as first responder 
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            txt.becomeFirstResponder()
        }
    }
    

    如果您有多个文本字段,则必须将第一个文本字段设置为第一响应者。

    【讨论】:

    • 成功了!谢谢。我不知道为什么我没想到。
    猜你喜欢
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    相关资源
    最近更新 更多