Last active
April 28, 2017 20:35
-
-
Save tikipatel/250d3ec9254bb75fa4ff to your computer and use it in GitHub Desktop.
Auto-expanding UITableViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} |
Author
tikipatel
commented
Feb 24, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment