Skip to content

Commit

Permalink
Fixing issue vikmeup#440 - How i can add function textFieldDidChange …
Browse files Browse the repository at this point in the history
…to SCLAlertView
  • Loading branch information
spneshaei committed Jul 7, 2021
1 parent f08ec93 commit edc3363
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ open class SCLAlertView: UIViewController {
fileprivate var inputs = [UITextField]()
fileprivate var input = [UITextView]()
internal var buttons = [SCLButton]()
fileprivate var onTextChanged: ((String) -> Void)?
fileprivate var selfReference: SCLAlertView?

public init(appearance: SCLAppearance) {
Expand Down Expand Up @@ -529,7 +530,7 @@ open class SCLAlertView: UIViewController {
}
}

open func addTextField(_ title:String?=nil)->UITextField {
open func addTextField(_ title: String? = nil, onTextChanged: ((String) -> Void)? = nil) -> UITextField {
// Update view height
appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextFieldHeight)
// Add text field
Expand All @@ -548,9 +549,21 @@ open class SCLAlertView: UIViewController {

contentView.addSubview(txt)
inputs.append(txt)

if let onTextChanged = onTextChanged {
self.onTextChanged = onTextChanged
txt.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
}

return txt
}

@objc open func textFieldDidChange(_ textField: UITextField) {
if let onTextChanged = onTextChanged, let text = textField.text {
onTextChanged(text)
}
}

open func addTextView()->UITextView {
// Update view height
appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextViewdHeight)
Expand Down

0 comments on commit edc3363

Please sign in to comment.