2. On viewDidLoad, set save button enabled to false.
3. Create a function to handle the text change event.
- If text is empty, set to disabled, else set to enabled.
func nameChanged(notification: NSNotification) {saveButton.enabled = validateFields()}func validateFields() -> Bool {return !nameTextField.text!.isEmpty}
3. Register a notification for text change inside the viewDidLoad function
NSNotificationCenter.defaultCenter().addObserver(self, selector: "nameChanged:", name: UITextFieldTextDidChangeNotification, object: nameTextField)4. Unregister observer when leaving the page.
NSNotificationCenter.defaultCenter().removeObserver(self)
No comments:
Post a Comment