SCLAlertView - 专注于文本字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SCLAlertView - 专注于文本字段相关的知识,希望对你有一定的参考价值。

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

答案

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

@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()
    }
}

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

以上是关于SCLAlertView - 专注于文本字段的主要内容,如果未能解决你的问题,请参考以下文章

如何专注于表格视图中视图之外的文本字段?

didSelectItemAt 在 SCLAlertView 中不起作用

专注于工具提示中的文本字段

jQuery:如何专注于输入文本字段,使光标位于文本的末尾?

JavaScript jquery - 专注于页面上的第一个文本输入字段

iOS Safari(移动)和 Angular Material UI:专注于输入字段时不需要的闪烁文本