【问题标题】:UITableView doesn't display based on its height in iOS 7UITableView 在 iOS 7 中不根据其高度显示
【发布时间】:2013-10-05 08:01:03
【问题描述】:

我有一个可展开的 UITableView,它可以在用户按下按钮时展开/折叠。 方法是我在按下按钮时更改其内容,并将 contentSize.height 分配给 tableview 的高度。它在 iOS 6 中正常工作。

然而,在 iOS 7 中,无论我为 tableview 的高度设置什么值,它都显示为高度从未改变,新内容被截断。高度似乎坚持故事板中的原点高度。但是如果我打印tableview的高度,就是我设置的值。

这是我如何改变它的高度:

//Do some change to the content...
[tableview reloadData];
NSLog(@"height: %f, contentHeight: %f", tableview.frame.size.height, tableview.contentSize.height);// print height: 60, contentHeight: 160
CGRect frame = tableview.frame;
frame.size.height = tableview.contentSize.height;
tableview.frame = frame;
NSLog(@"height: %f, contentHeight: %f", tableview.frame.size.height, tableview.contentSize.height);// print height: 160, contentHeight: 160

有什么想法吗?

附言表格视图位于 UIScrollView 中。 (如果重要的话。)

【问题讨论】:

  • 默认情况下,每个UITableView 都在UIScrollView 中。如果您手动添加了另一个,那么您真的不应该这样做。
  • 你为什么把你的 UITableView 放在另一个 UIScolView 中?你真的需要吗?事实上,就像 Marko 所说,UITableView 已经继承自 UIScrollView,所以删除你的滚动视图容器可能会满足你的需求。

标签: ios uitableview ios7


【解决方案1】:

我认为你的问题是滚动视图。 试试这样的:

CGRect screen = [[UIScreen mainScreen] bounds];
CGSize scrollViewContentSize = CGSizeMake(screen.size.width, screen.size.height);
[self.scrollView addSubview:tableview];
scrollViewContentSize.height += tableview.frame.size.height;
[self.scrollView setContentSize:scrollViewContentSize];
[self.view addSubview:self.scrollView];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2023-04-11
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 2013-12-28
    相关资源
    最近更新 更多