简体   繁体   中英

How to make flexible tableview within scrollview in swift?

I want to use tableview inside scrollview. and I want to give height to the tableview as 150 or greater than but as soon as I am doing so It's showing error. My actually I have to implement collasible cell in the tableview. So I do't want to give height of the table programatically. I want it should be adjustable by storyboard.

在此处输入图像描述

I think your method is not efficient. cz tableview scrollable to, why do you need scroll view. let's make it simple, try this:

  1. create tableview with 4 section
  2. create a view each section (workoutnamecell, workoutlistcell, buttonaddcell, and notecell)
  3. and on function tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath), you will append list off workout list rows. it will make your tableview dynamic

if you don't want use tableview only, make tableview and scrollview high contsraint dinamicly. make sure your scrollview high is higher than your tableview. and last disable userinteraction on your tableview. so your tableview will stack on your scrollviw.

Thanks, CMIW

A UITableView within a UIScrollView is never a good idea. It can lead to many problems. My suggestion would be:

  1. Either make the whole thing a UITableView with all the items currently in the scrollview beeing inside UITableViewCells
  2. Or use a vertical UIStackView that you will dynamically update to expand / collapse rows instead of a UITableView and have that in your scrollview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM