Swift 4 Textview goes to bottom of textview when press return key

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Swift 4 Textview goes to bottom of textview when press return key



When I press return button when editing my textview, it makes a new line where I currently am editing the textview and it automatically goes to the bottom of the textview text. I think it is because I am using Firebase to keep the textview in realtime text so it can update on all devices. When i remove the observer in the following code, it works like its supposed to:


override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ref = Database.database().reference()
textView.delegate = self




ref.child("Notes").observe(.value, with: (snapshot) in
let note = snapshot.value as? [String : String]

self.textView.text = note!["note"]

)



I also have this code to update the database with the text in the texview:


func textViewDidChange(_ textView: UITextView) //Fires when the textview text changes
print(textView.text)
self.ref.child("Notes/note").setValue(textView.text)




I think i am having a problem because it gets the text from the database and sets a new copy of the text into the textview how can i solve this problem?





Do you really want to update Firebase for every character typed into the text view? Why not wait until the text view loses focus?
– rmaddy
16 hours ago





I am trying to make a realtime notes app so it would great if i can figure this out by sending each character to the database so that different users can edit the same document
– Chris
16 hours ago






Maybe you should avoid setting the text view's text property if the value of note["note"] is the same as the current value.
– rmaddy
16 hours ago


text


note["note"]









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Mass disable jenkins jobs