【问题标题】:Height of UITableView is not changing programmatically [duplicate]UITableView 的高度没有以编程方式改变[重复]
【发布时间】:2015-06-30 06:40:22
【问题描述】:

当从超级视图中删除子视图时,我想根据数组中项目的大小来刷新和调整表视图的大小以填充到表视图中。我通过创建一个框架来做到这一点,该框架为每个增加的项目增加 50 的高度。这是我的代码

- (IBAction) doneAddingUsers:(id)sender {

    [self.crewTable setHidden:NO];
    [self.crewTable reloadData];
    self.crewTable.frame = CGRectMake(self.crewTable.frame.origin.x, self.crewTable.frame.origin.y, self.crewTable.frame.size.width, [crewArray count]*50);

    NSLog(@"height: %f", crewTable.frame.size.height);
    [self.view bringSubviewToFront:self.crewMembersView];
    [self.crewMembersView removeFromSuperview];
}

在日志中它显示了正确的高度,但在 UI 中它似乎没有改变表格视图的高度。我也禁用了滚动

提前致谢

【问题讨论】:

  • 我没有测试过这个,但我想你应该设置框架然后调用reloadData。而不是你所拥有的那样。

标签: ios uitableview


【解决方案1】:

您可以这样做,而不是在 doneAddingUsers: 中设置框架:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int count = [crewArray count];

    //Set the height of the tableview
    CGRect frame = self.tabPackageList.frame;

    frame.size.height = (count * 50);

    [self.tabPackageList setFrame:frame];

    // Return the number of rows in the section.
    return count;
}

【讨论】:

    猜你喜欢
    • 2014-07-05
    • 2012-08-13
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 2014-01-22
    • 2017-04-25
    相关资源
    最近更新 更多