IOSを勉強しているものなのですがTableView上にセルとともに可変するTextViewを作りたいと思いプログラムをしているのですがなかなかうまくいきません。
プログラムが悪いのでしょうかご教授お願いいたします。
import UIKit
class ViewController: UIViewController,UITextViewDelegate
{
@IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.estimatedRowHeight = 10000 tableView.rowHeight = UITableViewAutomaticDimension } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func textViewDidChange(_ textView: UITextView) { tableView.beginUpdates() tableView.endUpdates() }
}
extension ViewController: UITableViewDelegate
{
}
extension ViewController: UITableViewDataSource
{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomCell var str = "文字を入力してください" let index = str.index(str.startIndex, offsetBy: indexPath.row) str = str.substring(to: index) cell.cellLabel.text = str return cell }
}
<====================================================>
import UIKit
class CustomCell: UITableViewCell
{
@IBOutlet weak var cellLabel: UITextView! override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
}
}
あなたの回答
tips
プレビュー