我有一个可展开的 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/