I created TextField using UITextView.
I would like to store the text written there in the Firestore.
It is not stored in the normal way.
Please let me know what I should do.
// Multiple lines of TextField created
structureMultiLineTextField:UIViewRepresentable{
@Binding var text: String
func makeCoordinator()->Coordinator {
MultiLineTextField.Coordinator (parent1:self)
}
func makeUIView (context:Context) - > UITextView {
let textView = UITextView()
textView.delegate=context.coordinator
textView.isScrollEnabled=true
textView.isEditable=true
textView.isUserInteractionEnabled=true
textView.text="xxx"
textView.textColor=UITraitCollection.current.userInterfaceStyle==.dark?UIColor(displayP3Red:0.4, green:0.4, blue:0.4, alpha:1): .lightGray
textView.font=.systemFont(ofSize:17)
textView.backgroundColor=UITraitCollection.current.userInterfaceStyle==.dark?UIColor (displayP3Red:0.2, green:0.2, blue:0.2, alpha:1):UIColor (displayP3Red:0.9, green:0.9, blue:0.9, alpha:1)
return textView
}
func updateUIView(_uiView:UITextView, context:Context){
}
class Coordinator:NSObject,UITextViewDelegate{
var parent —MultiLineTextField
init(parent1:MultiLineTextField) {
parent = parent1
}
functextViewDidBeginEditing(_textView:UITextView){
if self.parent.text=="{
textView.text=""
textView.textColor=.black
}
}
internal func textViewDidEndEditing(_textView:UITextView){
if self.parent.text=="{
textView.text="xxx"
textView.textColor=UITraitCollection.current.userInterfaceStyle==.dark?.darkGray:.lightGray
}
}
}
}
// firestore processing, text obtained in MultiLineTextField
db.collection("xxx").document("xxx").setData([..., "text":self.text,...]){(error) in
if error!=nil{
print(error?.localizedDescription)!)
return
}
}
}
Dear nekketsuuuu,
I am the same person as user40929, and I have a different account.
Sorry for not being able to log in as user40929.(Also, due to the low credit rating, I cannot add comments, so I will write here.)
The situation is that when I add to the Firestore, no errors occur, but no values were added to the target fields of the Firestore that I plan to add.(The field itself is done)
Thank you for your cooperation.
© 2024 OneMinuteCode. All rights reserved.