【问题标题】:How to resize UIScrollView/ContainerView's height according to UITableview number of rows?如何根据 UITableview 的行数调整 UIScrollView/ContainerView 的高度?
【发布时间】:2015-07-09 22:26:22
【问题描述】:

这是我在故事板中的 ViewController:

UIView(控制器)
-UIScrollView
--UIView
--UIView
--容器视图
---UITableView(嵌入ContainerView)

UITableView 具有动态原型。
我的问题是如何更改 UIScrollView 和 ContainerView 的高度以适应 UITableView 的行数?

当 UITableView 中有很多行时,我希望能够使用我的 UIScrollView(不是 UITableView 的 UIScrollView)向下滚动。

【问题讨论】:

    标签: ios objective-c iphone uitableview uiscrollview


    【解决方案1】:

    您可以应用以下逻辑来增加滚动视图的高度。

    height = 总行数(数组或字典计数)* 您的单元格高度(单元格高度应该是静态的)。

    使用以下计算,您将找到总高度并将此高度设置为表格高度或滚动视图高度。

    [scrollview setContentSize:CGMakeSize(scrollview.contentSize.width,tableView.frame.size.height)];

    [scrollview setContentSize:CGMakeSize(scrollview.contentSize.width,height)];

    我希望这对你有用。

    谢谢

    【讨论】:

      【解决方案2】:

      每次行数发生变化时,只需更新UIScrollViewcontentSize

      请看下面的示例

      - (void)updateScrollViewContentSize
      {
          float cellHeight = 40;
          int numberOfRows = [noOfItemsInArray count];
      
          float sizeOfContent = cellHeight * numberOfRows;
      
          scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-17
        • 1970-01-01
        • 2012-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多