Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 根据内容大小调整TabeView的高度,使其仅在不适合视图时滚动?_Objective C_Uitableview - Fatal编程技术网

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

希望有帮助。

添加一些代码。让我们看看你试过什么。