无法在iOS中调整TableView Height的大小 [英] TableView Height can not resize in IOS

查看:58
本文介绍了无法在iOS中调整TableView Height的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做这样的事情,我有一个 UIViewControler .因此,在故事板中,我将 UITableView 拖放到视图中.我应该在该表视图中显示一些自定义的行.但我想动态更改该表格视图的高度.(根据表格视图内的行数).

I am trying to do something like this, i have a UIViewControler. So in my story board i drag and drop a UITableView to the view. I'm supposed to show few customized rows in that table view. but i want to dynamically change the height of that table view.(According to the row count inside the table view).

我尝试下面的代码,但到目前为止没有任何效果.

i tried like below code, but nothing worked so far.

CGRect tvframe = [tableView frame];
 [tableView setFrame:CGRectMake(tvframe.origin.x, 
                            tvframe.origin.y, 
                            tvframe.size.width, 
                            tvframe.size.height + 20)];

我也尝试过这个

    CGRect frame = self.tableView.frame;
    frame.size = self.tableView.contentSize;
    self.tableView.frame = frame;

但是对我没有任何帮助..请有人告诉我我该怎么做.

but nothing worked for me.. please some one tell me how do i do this.

谢谢.

推荐答案

在Autolayout中,如果要更改框架,请尝试使用约束( NSLayoutConstraint IBOutlet ).

In Autolayout if you want to change the frame then try the constraints (IBOutlet of NSLayoutConstraint).

设置约束出口,并通过以下方式更改 constant 的值:

Set the constraint outlets and change constant value by :

self.sampleConstraint.constant = 20
self.view.layoutIfNeeded()

这篇关于无法在iOS中调整TableView Height的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆