UITextView Showing the Save Button after Edits to Content

I have one last finishing touch on my first app and need some advice.

It is a list view with a detail view. In the detail view there is a UITextView that is pre-populated with content. However it is set up so the user can edit and save changes to that content. I also have a functioning Save button in the navigation bar.

The thing I am trying to do is to disable the Save button until the user actually makes an edit to the text. I have the following code in the view controller for the detail view, but I know it is not exactly right because I am not checking for empty but for changed.

 @IBAction func textEditingChanged(_ sender: UITextView) {
    updateSaveButtonState()
  }
  
  func updateSaveButtonState() {
   // let titleText = titleTextField.text ?? ""
    let descriptionText = descriptionTextView.text ?? ""
    saveButton.isEnabled = !descriptionText.isEmpty
  }

Any help in finding a solution to this will be greatly appreciated.

Thanks.

Hi @rouviere,
You could capture the text int he UITextField when the editing starts, and with every change, you can check if it is the same or not, that would provide you with if it was changed or not.

cheers,

Jayant

This topic was automatically closed after 166 days. New replies are no longer allowed.