Set TableView height by the number or rows

前端 未结 9 1732
不思量自难忘°
不思量自难忘° 2021-01-31 10:40

I have got TableView in the MainstoryBoard and the number of rows is random every time. I want the height of the whole TableView to be fl

9条回答
  •  暖寄归人
    2021-01-31 11:17

    Note: when your are increasing the tableview height it will goes out side the view. and you will get a problem with scrolling.

    Ex: take a view inside that keep tableview and give constraints to left,right,bottom,top to Zero(0).

    now reload the tableview assume 2 rows each row height is 20 now total rows height is 40. its fine and gave those height to table view, Table view will show only 40 height (you can assign tableview height by taking constraints (or) table view content size both are give same height according to rows height).

    But if you reload 50 rows you will get scrolling problem because those rows height given to table view height, here table view height expands more than your screen height.

    To solve this problem you should use scroll view outside the tableview.

提交回复
热议问题