iOS 6 AutoLayout具有多个tableviews所有动态高度 [英] iOS 6 AutoLayout with multiple tableviews all dynamic heights

查看:187
本文介绍了iOS 6 AutoLayout具有多个tableviews所有动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我被卡住了。在我的应用程序中,我有一个产品视图。在此视图中,滚动视图中有两个嵌套的表视图。第一个tableview只有一个单元格并保存静态文本。这个文本长度是动态的,基于你选择的自豪感。第二个tableview包含多个单元格,这些单元格基于与该产品相关联的子产品数量。因此,在iOS 5中,根据第一个表视图中文本的大小,动态移动每个表视图的帧非常容易。然后我可以总结所有表视图的高度,这将是滚动视图的高度。问题是,当我打开自动布局时,事情变得清晰起来。从我的理解滚动视图已经改变。我们不能使用滚动视图的框架或内容大小。所以我做的第一件事就是改变了所有这些。我在下面做了以下。

Okay so I am stuck. In my app I have a product view. On this view there are two nested table views inside a scroll view. The first tableview is only one cell and holds static text. This text length is dynamic based on which proudct you pick. The second tableview consists of multiple cells based on how many sub products are linked to that prodcuct. So in iOS 5, it was pretty easy to dynamically move the frame of each table view based on how large the text was in the first table view. I could then just sum up the height of all the table views and that would be the height of the scroll view. The issue is when I turned on auto layout things got hozed. From my understanding scrollviews have changed. We cannot use the frame or content size of a scroll view. So the first thing I did was changed all that over to contraints. I did the following below.

CGSize descriptionSize = [descriptionDetail sizeWithFont:
                         [UIFont systemFontOfSize:14]
                         constrainedToSize:CGSizeMake(320, CGFLOAT_MAX)
                         lineBreakMode:NSLineBreakByWordWrapping];

self.theScroller.translatesAutoresizingMaskIntoConstraints= NO;
[self.theScroller setContentInset:UIEdgeInsetsMake(0, 0, (descriptionSize.height+ (43 * [Solution count])), 0)];

现在上面的内容完美无瑕。滚动视图滚动很好,并且是自动布局的正确高度。

Now this above works flawless. The scroll views scrolls great and is the correct height with auto layout on.

现在我坚持的部分是如何基于上下动态移动两个tableviews描述的时间长度或第二个表视图中有多少个单元格?表格视图的框架似乎对它们所在的位置没有任何影响。我试着搞乱了约束,但似乎没有得到任何结果。任何帮助将不胜感激。谢谢

Now the part I am stuck on is how do I dynamically move the two tableviews up and down based on how long the description is or how many cells are in the second table view? The frames of the table view dont seem to have any effect on where they are located. I tried messing around with the contraints but didn't seem to get anywhere. Any help would be greatly appreciated. Thanks

推荐答案

我认为使用单个UITableView可以让生活变得更轻松。

You could make life easier for yourself by doing all this using a single UITableView I think.

你的其中UIImageView的上层UIView是tableHeaderView,你的第一个单行UITableView是UITableView的第一部分,你的带有动态内容的表视图位于UITableView的更多部分。

Your upper UIView with the UIImageView in it is the tableHeaderView, your first 'single row UITableView' is the first section in the UITableView and your table view with dynamic content is in further sections of the UITableView.

这篇关于iOS 6 AutoLayout具有多个tableviews所有动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆