I have a UITableViewController that utilizes custom cells. Within the custom cell is a UITextView and a UIButton. I need for the selected tableView cell to fit the multiple lines of text that may be input by the user, as the user is typing. An app that demonstrates this perfectly would be iPhone's pre-installed Reminders app. Currently in my app, the tableView cell's height remains static and the textView enables scrolling when necessary in order to accommodate multiple lines of text.
I tried implementing the solutions in this post (Dynamically change cell's height while typing text, and reload the containing tableview for resize) which seemed to ask the same question, however, the post is nearly 3 years old and even if the answer is still valid, there's not enough sample code present for me to understand how to implement the answer. I did my best with no luck and cleared my current code of any previous attempts so that it's presently a clean slate as far as this desired feature is concerned. It would be amazing to see an answer that includes sample code in Swift 5.
Here is the custom cell class if it would be useful:
class newNoteTableViewCell: UITableViewCell {
@IBOutlet weak var lyricsField: UITextView!
@IBOutlet weak var recordButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
@IBAction func recordButtonPressed(_ sender: UIButton) {
}
}
And my cellForRowAt, which is currently the only table view delegate method implemented other than numberOfRowsInSection:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "lyricsCell", for: indexPath) as! newNoteTableViewCell
cell.lyricsField.delegate = self
cell.lyricsField.tag = indexPath.row
if let safeLyrics = lyrics {
if indexPath.row < safeLyrics.count {
cell.lyricsField.text = safeLyrics[indexPath.row].text
} else {
cell.lyricsField.text = ""
}
}
return cell
}




