【问题标题】:Resizing tableview height programmatically以编程方式调整 tableview 高度
【发布时间】:2013-01-09 05:31:32
【问题描述】:

我在 xcode 4.5 中使用故事板。

在我的应用程序中有 2 个视图,view1 和 view2。

每个视图都有一个表格视图。

导航控制器连接到视图。

我正在尝试根据 Iphone 显示屏的大小更改 tableview 的高度。

我正在使用以下代码:

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];    

// Verify if the screen is iphone 5

if ([[UIScreen mainScreen] bounds].size.height == 568){

    // Resize table hight

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

问题是应用启动出现view1时代码没有任何作用。

但是当我移动到 view2 然后回到 view1 时,调整大小就会生效。

我不明白为什么应用程序启动时调整大小不生效。

【问题讨论】:

    标签: xcode resize height tableview


    【解决方案1】:

    您是否尝试将代码移至 ViewWillAppear?那应该可以解决问题。

    【讨论】:

    • 将代码移动到 ViewWillAppear 不起作用。我通过为 Iphone 3/4 和 Iphone 5 创建单独的视图解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2012-08-13
    • 2020-01-11
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多