在swift中的TableView单元格中编辑文本视图
我被卡住了:我有一个由我制作的.xib单元格填充的TableView。每个单元格都包含一个可编辑的文本视图。 我正试图将用户在这些文本视图中输入的文本保存在Firebase数据库中。我不想实现任何按钮,文本应该在TextView编辑结束后立即保存 我试图将.xib文件中的TextView连接到UITableViewCell类,但它不允许我将其作为iAction连接,而只能作为outlet或outlet连接连接 请帮帮我,谢谢在swift中的TableView单元格中编辑文本视图,swift,xcode,uitableview,textview,tableview,Swift,Xcode,Uitableview,Textview,Tableview,我被卡住了:我有一个由我制作的.xib单元格填充的TableView。每个单元格都包含一个可编辑的文本视图。 我正试图将用户在这些文本视图中输入的文本保存在Firebase数据库中。我不想实现任何按钮,文本应该在TextView编辑结束后立即保存 我试图将.xib文件中的TextView连接到UITableViewCell类,但它不允许我将其作为iAction连接,而只能作为outlet或outlet连接连接 请帮帮我,谢谢 您需要在应用程序中实现UITextFieldDelegate UIT
UITextFieldDelegate
UITableViewCell
classUITextView
的委托
连接到单元类func textViewDiEndediting(UITextView)
中执行任何操作在这里您可以阅读更多内容:我解决了用文本字段替换文本视图的问题,这些文本字段看起来可能相同,但可以链接到UITableViewCell.swift作为iAction。 因此,我编写了代码来更新IBAction内数据库的“注释”部分:
@IBAction func commentTextFieldToggle(_ sender: UITextField) {
if commentTextField.text != "" {
let comment = commentTextField.text
// I declared the next 7 constants to retreive the exact position of the string "comment" that I want to change
let date = dateLabel.text!
let time = timeLabel.text!
let year = date.suffix(4)
let day = date.prefix(2)
let partialMonth = date.prefix(5)
let month = partialMonth.suffix(2)
//I use this "chosenDate" constant to retreive the database query that I previously saved using the date in the below format as index:
let chosenDate = "\(year)-\(month)-\(day) at: \(time)"
let commentsDB = Database.database().reference().child("BSL Checks")
commentsDB.child((Auth.auth().currentUser?.uid)!).child(String(chosenDate)).child("Comments").setValue(comment) {
(error, reference) in
if error != nil {
print(error!)
} else {
print("User Data saved successfully")
}
}
}
}
嗯。。。我正试图跟随你的脚步,但我需要更多的帮助:1。-类TableViewCell:UITableViewCell,UITextViewDelegate{…2.-self.textView.delegate=self 3??