ios - UITableView 的高度未以编程方式更改

标签 ios uitableview

<分区>

当从 super View 中删除 subview 时,我想根据数组中要填充到 TableView 中的项目的大小来刷新 TableView 并调整其大小。我通过创建一个框架来做到这一点,该框架将每个增加的项目的高度增加 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 中它似乎没有改变 TableView ​​的高度。我也禁用了滚动

提前致谢

最佳答案

您可以这样做,而不是在 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;
}

关于ios - UITableView 的高度未以编程方式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221832/

上一篇:c# - 在 UINavigationBar 中将图像左对齐

下一篇:ios - 从自定义相册 ios 中删除照片

相关文章:

ios - 如何不返回 UITableviewCell

ios - 仅用于单个表部分的动态 UITableViewCell 高度

ios - 无法在 searchBar 方法中更改 UITableView 框架

iphone - iOS 普通表以编程方式根据日期对行进行分类

swift - 添加到 TableView 时 Realm 项会出现两次

ios - UICollectionView - 向页脚 View 添加操作

ios - 如何调试 APIService 的代码

ios - 错误域=NSCocoaErrorDomain 代码=-1 "(null)"移动.mov 到相机胶卷时

ios - 如何以编程方式停止 SMS 预览

ios - 需要使用 Swift 在 UITableView 中的每一行之后显示部分