the button is disabled when text view is empty else is enabled

后端 未结 3 672
庸人自扰
庸人自扰 2021-01-26 03:12

I\'m developing note app, when the text view is empty the done button should be disabled so user could not be able to save empty notes into data base, else the button should be

3条回答
  •  庸人自扰
    2021-01-26 03:49

    1. Make your view controller conform to UITextViewDelegate protocol
    2. In Interface Builder, connect the delegate on the text view to your view controller.
    3. Add the following function to your view controller:

    func textViewDidChange(textView: UITextView) {
        if textView == self.textView {
            self.doneButton.enabled = !textView.text.isEmpty
        }
    }
    

提交回复
热议问题