ios - 如何在 viewdidload 中以编程方式调整 TableView 的高度

标签 ios uitableview

如何在 viewdidload 中以编程方式调整我的 tableview 高度?实际上我在我的应用程序中有一个 View 我希望 View 将加载然后 uivew 将隐藏 ang tableview 高度将增加?怎么做到的?我在 viewdidload 中添加了这些行,但没有任何反应?

- (void)viewDidLoad {
    [super viewDidLoad];
 CGRect tableFrame = [tableListView frame];
tableFrame.size.height = 127; 
[tableListView setFrame:tableFrame];
}

下面是我的屏幕截图我想隐藏那个 greycolourview 并想增加我的 tableview 高度。 enter image description here

screen shot

最佳答案

试一试:

1.

这应该是您对 tableView 的约束:

enter image description here


2.

//declare a constraint outlet and connect it
IBOutlet NSLayoutConstraint *constraintGrayViewBottom;

3.

这是灰色 View 的底部约束,即:constraintGrayViewBottom
如图所示选择底部约束,然后在右侧单击并拖动引用导出连接到 viewController,并将其连接到 constraintGrayViewBottom

enter image description here


4.

以处理约束变化为例:

-(void)viewDidAppear:(BOOL)animated {
    constraintGrayViewBottom.constant = -60;

    [UIView animateWithDuration:1
                     animations:^{
                         [self.view layoutIfNeeded];
                     }];
}

关于ios - 如何在 viewdidload 中以编程方式调整 TableView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27173025/

相关文章:

ios - UISearchController 不会向上移动我的 UITableView

ios - 刷新数据后 IBOutlet nil

android - PhoneGap - 防止屏幕方向改变

swift - 将 UIToolBar 添加到 TableViewController (Swift)

ios - 连接 IBOutlet 导致 nsunknownkey 异常

ios - Swift——需要在自定义 TableView 单元格中单击并拖动 UIImageView

objective-c - 如何显示来自 NSMutableDictionary 的 NSMutableArray 的动态值列表?

ios - 在恢复设置上一个 View

ios - ALAssetsGroup,如何检查是否存在?

iphone - iOS 设备因未知原因崩溃