Objective c 根据内容大小调整TabeView的高度,使其仅在不适合视图时滚动?
我已经检查了所有与此相关的答案。我的代码只有在禁用或启用从故事板而不是从代码滚动时才有效 它始终显示内容大小高度和表视图高度相同。我没有使用自动布局Objective c 根据内容大小调整TabeView的高度,使其仅在不适合视图时滚动?,objective-c,uitableview,Objective C,Uitableview,我已经检查了所有与此相关的答案。我的代码只有在禁用或启用从故事板而不是从代码滚动时才有效 它始终显示内容大小高度和表视图高度相同。我没有使用自动布局 [tableView reloadData]; tableView.frame.size.height = tableView.contentSize.height; 试试这个 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self
[tableView reloadData];
tableView.frame.size.height = tableView.contentSize.height;
试试这个
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self adjustHeightOfTableview];
}
写入AdjustHeightOfTable将此方法视为
- (void)adjustHeightOfTableview
{
CGFloat height = self.tableView.contentSize.height;
CGFloat maxHeight = self.tableView.superview.frame.size.height - self.tableView.frame.origin.y;
// if the height of the content is greater than the maxHeight of
// total space on the screen, limit the height to the size of the
// superview.
if (height > maxHeight)
height = maxHeight;
// now set the frame accordingly
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = self.tableView.frame;
frame.size.height = height;
self.tableView.frame = frame;
// if you have other controls that should be resized/moved to accommodate
// the resized tableview, do that here, too
}];
}
希望有帮助。添加一些代码。让我们看看你试过什么。