I have been having an issue regarding a UITextView inside a custom cell. The textView works perfectly besides my issue.
I have the UITextViewDelegate methods setup so when something happens to the textview, I have those methods connected.
I would like to know how I can have my custom cell dynamically increase it's height as the user types. Once the user hits the end of the line of the textview, to also have the textview add another line automatically.
I have been searching online for a while, and most of the examples for this issue are in objective c. Not much swift code. I would appreciate any help.
I have my cell hooked up in the tableview file as such..
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: cellCustom = the_TableView.dequeueReusableCellWithIdentifier("cell") as! cellCustom
return cell
}
In the custom cell file, I have the delegates set up...
func textViewDidChange(textView: UITextView) {
}
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
return true
}
I have tried some things like ...
self.textview.sizeToFit()
self.the_TableView.rowHeight = UITableViewAutomaticDimension
self.the_TableView.estimatedRowHeight = 47
When I did that, the textview took all the text, but did not increase in size until I resigned it's first responder and scrolled up for the cell to be gone. Then when the cell bounces back down, it updates.
I have already added all the constraints and the project has zero risks or errors and works perfectly.
To clarify, I would like the uitextview to change height based on the content the user types while they are typing it, meaning the custom cell and tableview would have to update. Think of the clear app on iPhone. It's like that. The cell updates dynamically as the user types, increasing in height, while adding a new line once the user reaches the end. That is what I'm reaching for.
Though I am not new to developing by any means, I never really got to this point in development before. Any help would be extremely appreciated. Since I have my custom cell in another file, I have difficulty accessing my cell elements from the tableview file. Still a novice I guess. Thanks for reading this.
See Question&Answers more detail:
os