ios - UITableView 在 iOS 7 中不根据其高度显示

标签 ios uitableview ios7

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

然而,在 iOS 7 中,无论我为 tableview 的高度设置什么值,它都显示为高度从未改变,新内容被截断。高度似乎坚持 Storyboard中的原点高度。但是如果我打印 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

有任何想法吗?

p.s.表格 View 位于 UIScrollView 中。 (如果重要的话。)

最佳答案

我认为你的问题是 ScrollView 。
尝试这样的事情:

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];

关于ios - UITableView 在 iOS 7 中不根据其高度显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195433/

相关文章:

ios - 从自定义单元格中的按钮调用 UIActivityViewController

ios - UITableViewCells 显示在其他类型的单元格上

ios - Facebook News 纸质应用,全尺寸图像视差效果

iOS - AVSpeechSynthesizer 暂停和继续说话问题

ios - 如何添加圆到矩形? UIBezierPath

ios - Stackview 轴更改被延迟

ios - ios7 中的 CLLocationManager 停止工作

ios - ios图表整数转换

ios - CollectionView 单元格意外行为 swift

ios - Assets 目录中的 Launch Image 只有 2x 和 R4 的空间