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
This works for ios 7 too
this goes into your tableviewcell
protocol HeightForTextView {
func heightOfTextView(height: CGFloat)
}
class TableViewCell: UITableViewCell {
@IBOutlet weak var textView: UITextView!
var delgate:HeightForTextView?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func textViewDidChange(textView: UITextView) {
var fixedWidth: CGFloat = textView.frame.size.width
var newSize: CGSize = textView.sizeThatFits(CGSizeMake(fixedWidth, CGFloat.max))
if let iuDelegate = self.delgate {
iuDelegate.heightOfTextView(newSize.height)
}
}
}
your tableview controller should be
class TableViewController: UITableViewController,HeightForTextView {
var textViewHeight = CGFloat()
//In your cell for row method set your your delegate
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell
cell.delgate = self
return cell
}
//delegate method
func heightOfTextView(height: CGFloat) {
textViewHeight = height
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return textViewHeight + 70
}
}