This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet weak var textField: UITextField! | |
@IBOutlet weak var actionButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.actionButton.enabled = false | |
} | |
@IBAction func onActionPressed(sender: AnyObject) { | |
let success = self.sendMessage(self.textField.text) | |
let message = success ? "Message sent" : "Message not send" | |
UIAlertView(title: nil, message: message, delegate: nil, cancelButtonTitle: "Ok").show() | |
if (success) { | |
self.textField.text = "" | |
self.validateActionButton() | |
} | |
} | |
private func validateActionButton() { | |
self.actionButton.enabled = countElements(self.textField.text) > 0 | |
} | |
private func sendMessage(message: String) -> Bool { | |
/// some logic here ... | |
return true | |
} | |
@IBAction func textFieldDidChange(sender: AnyObject) { | |
self.validateActionButton() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment