Skip to content

Instantly share code, notes, and snippets.

@tikipatel
Last active April 28, 2017 20:35
Show Gist options
  • Save tikipatel/250d3ec9254bb75fa4ff to your computer and use it in GitHub Desktop.
Save tikipatel/250d3ec9254bb75fa4ff to your computer and use it in GitHub Desktop.
Auto-expanding UITableViewCell
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.estimatedRowHeight = 44
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.dataSource = self
self.tableView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as! MyTableViewCell
cell.myTextView.delegate = self
cell.myTextView.scrollEnabled = false
return cell
}
}
extension ViewController: UITableViewDelegate, UITextViewDelegate {
func textViewDidChange(textView: UITextView) {
tableView.beginUpdates()
tableView.endUpdates()
}
}
class MyTableViewCell: UITableViewCell {
@IBOutlet weak var myTextView: UITextView!
}
@tikipatel
Copy link
Author

Preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment