iOS 8 auto-sizing UITableViewCell with UITextView

前端 未结 6 1521
余生分开走
余生分开走 2021-02-12 12:11

iOS 8 introduced a way for tableViews to automatically adjust their cell\'s height based on their content (via AutoLayout).

// in viewDidLoad:
tableView.rowHeigh         


        
6条回答
  •  离开以前
    2021-02-12 12:54

    If everything is set up properly (Auto Layout constraints) you do not have to calculate anything yourself.

    All you have to do is disable UITextView's scrolling enabled property then on textViewDidChange call tableView.beginUpdates() and tableView.endUpdates().

    For a detailed explanation, check out a post I wrote which also includes a working sample project.

提交回复
热议问题