简体   繁体   English

UITableView在UIScrollView内部具有动态高度:

[英]UITableView with dynamic height inside UIScrollView:

I have a screen with UINavigationController and UITabBar . 我有一个带有UINavigationControllerUITabBar的屏幕。 The UINavigationController screen is a UIView (in figure below, in red), that haves an image in the top and a UIScrollView (in figure below, in green). UINavigationController屏幕是一个UIView (下图中,红色),在顶部有一个图像,而UIScrollView (下图中,绿色)是一个UIView The UIScrollView have two UILabel ("Some text") and a UITableView that DO NOT ENABLE SCROLLING. UIScrollView具有两个UILabel (“某些文本”)和一个不启用滚动的UITableView

在此处输入图片说明

Every time the list become bigger, i need to enlarge the tableview height, dynamically. 每当列表变大时,我就需要动态地扩大tableview的高度。 At the same time, I think I need to enlarge the UIScrollView . 同时,我认为我需要放大UIScrollView See the image below: 见下图:

在此处输入图片说明

How can I define the dynamical height to UITableView and UIScrollView ? 如何定义UITableViewUIScrollView的动态高度?

My goal is: Every time the list become bigger, the UIScrollView become bigger too. 我的目标是:每当列表变大时, UIScrollView变大。

My environment: 我的环境:

  • My UITableView DO NOT ENABLE SCROLLING 我的UITableView无法启用滚动
  • I am using XCode 4.6 and the view is a FreeForm 我正在使用XCode 4.6,并且视图是FreeForm
  • My view is using AutoLayout 我的看法是使用自动版式

I tried to do this setting just the UItableview height , without success. 我尝试仅通过UItableview height进行此设置,但没有成功。

How can I do this? 我怎样才能做到这一点?

You can calculate the height of table view bin the method 您可以计算表格视图bin的高度的方法

heightForCellAtIndexPath: 

in this method you pass the height of each row in this you can calculate height by creating a globale variable and in this variable add the row height each time. 在此方法中,您可以传递每一行的高度,在此方法中,您可以通过创建全局变量来计算高度,并在此变量中每次添加行高。

or you can find it by having no of rows * height of a row in height of a row is constant. 或者您可以通过没有行数找到它*行高在行高中是恒定的。

may this will help you. 可能会对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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