我是 ios 新手,遇到以下问题。
我想根据表格视图中元素的数量增加和减少表格视图的高度。如果在输入时客户端在输出时给出 3 个或超过 3 个元素,我希望看到一个比默认值大 2 行的表格视图。当输出的元素数量为 2 或 1 时,我将看到默认的表格视图高度。宽度将相同。这该怎么做?
这是我的代码:
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];
    }
在这种情况下,当输入元素进入时,表格视图的宽度和高度都可以,但取决于 inputlist 中的元素数量 - 表格视图在 ios Screen 上上下移动。为什么?