gpt4 book ai didi

ios 增加/减少tableview的大小

转载 作者:行者123 更新时间:2023-11-29 03:31:34 28 4
gpt4 key购买 nike

我是 ios 新手,遇到以下问题。

我想根据表格 View 中元素的数量增加和减少表格 View 的高度大小。如果在输入时客户端在输出时给出 3 个或超过 3 个元素,我希望看到一个比默认行大 2 行的 TableView 。当输出的元素数量为 2 或 1 时,我将看到默认的表格 View 高度。宽度将相同。如何做到这一点?

这是我的代码:

if (inputList.count>2)
{
CGRect bounds = [self.tableView bounds];
[self.tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
bounds.size.height + 50)];
CGRect tableFrame = [ self.predictiveDialog frame];
tableFrame.size.height=75;
[self.tableView setFrame:tableFrame];

}
else
{
NSLog(@"decrease size");

[self.tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
bounds.size.height - 50)];
CGRect tableFrame = [ self.predictiveDialog frame];
tableFrame.size.height=44;
[self.tableView setFrame:tableFrame];

}

在这种情况下,当输入元素进入时,tableview 宽度和高度都可以,但取决于 inputlist 中的元素数量 - tableview 在 ios Screen 上上下移动。为什么?

最佳答案

为什么不在 cellForRowAtIndexPath:(NSIndexPath *)indexPath delegate 方法中设置边界

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

if([indexPath row]>2)
{

[tableView setBounds:CGRectMake(self.tableView.frame.origin.x,
self.tableView.frame.origin.y,
self.tableView.frame.size.width,
self.tableView.frame.size.height + 50)];

}

// your other code
}

希望对您有所帮助。希望我正确理解你的问题。

关于ios 增加/减少tableview的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19701779/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com