SCLAlertView-Swift icon indicating copy to clipboard operation
SCLAlertView-Swift copied to clipboard

How to make button unable to click if the textfield don't have anything?

Open o1xhack opened this issue 8 years ago • 1 comments

Hi,

I need with Swift version. I know how to do this with the UIAlertView.

I have functio to track:

func nameFieldDidChange(_ textField:UITextField){
        self.currentAction.isEnabled = (textField.text?.characters.count)! > 0
    }

Then I have something in my alertfunc:

        alert.addAction(saveAction)
        saveAction.isEnabled = false
        self.currentAction = saveAction

currentaction is a bool type.

How can I do it with SCLAlertView?

o1xhack avatar Jun 20 '17 01:06 o1xhack

Did you try something like this?

let txt = alert.addTextField("Enter your name")
txt.delegate = self
btn = alert.addButton("Show Name") {
    print("Text value: \(txt.text ?? "NA")")
}

And set btn.isEnabled in UITextField delegate methods.

algrid avatar Aug 18 '17 22:08 algrid