tableViewの1つのCellに高さ可変のtextViewを設置しました。
それは問題なく動作しているのですが、全てのCellの高さが勝手に変わってしまいました。
Storyboard上ではCellの高さをデフォルトの44にしているのですが、それよりも2、3pxほど高くなってしまっているようです。
高さ可変のtextViewを機能させつつ、最初に読み込んだ時のCellの高さを44にしたいのですが、どのようにしたらよいでしょうか。
下記コードを削除するとセルの高さは戻りますが、textViewが可変ではなくなってしまいます。returnに44と入れてみても何も変わりませんでした。
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAutomaticDimension }
以下全コードです。
import UIKit class TableViewController: UITableViewController, UITextViewDelegate { @IBOutlet weak var textView: UITextView! override func viewDidLoad() { super.viewDidLoad() textView.delegate = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 13 } func textViewDidChange(_ textView: UITextView) { UIView.setAnimationsEnabled(false) tableView.beginUpdates() tableView.endUpdates() } override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAutomaticDimension } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAutomaticDimension } }
よろしくお願いいたします!
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/09 02:35
2017/01/09 02:42