ios - 在运行时增加 tableview 高度以包含全部内容

标签 ios swift uitableview

我使用 Swift 3 和 Xcode 8.1 创建了一个应用程序。我在其上方有一个 UITableview 和一个 UIView,通过单击其中的按钮显示和隐藏。当 UIView 出现时,UITableview 的最后一个单元格没有完全显示。

我在按钮中使用以下代码:

func filterShowHide ()
{
    if !isShown
    {
        filterImage.image = UIImage(named: "ME-Filter-re")
        self.filterView.isHidden = false
        self.tableViewTop.constant = 0
        // tableViewHeight.constant =  tableViewHeight.constant * 1.5
        isShown = true
    }
    else
    {
        filterImage.image = UIImage(named: "ME-Filter")
        self.tableViewTop.constant = -(self.HeaderView.frame.height) + self.filterBTN.frame.size.height
        self.filterView.isHidden = true
        isShown = false
        // tableViewHeight.constant =  tableViewHeight.constant / 1.5
    }
    UIView.animate(withDuration: 0.25) {
        self.view.layoutIfNeeded()
    }
}

有关详细信息,请参阅以下屏幕截图:

点击前和点击后

Before clicking After clicking

如何完整显示最后一个单元格?

最佳答案

我认为问题在于您的 tableview 高度仍然相同,并且在您更新顶部约束时它被推低了。

您应该将 TableView 底部约束设置为其 super View 的底部,或者您可以使用您用于 self.tableViewTop.constant 的值更新 tableView.contentInset.top

关于ios - 在运行时增加 tableview 高度以包含全部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45822313/

相关文章:

arrays - 如何在 iOS Swift 中将值数组附加到 tableView 中?

ios - 使用 tableView.reloadSections([0], with : UITableView. RowAnimation.right) 时从未调用 UITableView drop 方法

iOS 通过 POST 到 Web 服务器 - 字符串被切断?

ios - 从 coredata 加载图像,tableview 滚动不流畅

swift - 使用 React native 框架的 Eddystone 信标扫描

swift - Int 和 Double 在 Swift 中共享一个公共(public)父类

ios - 通过在 FirstViewController 中输入城市名称来更改 UITableView 数据

iphone - 后台的 Restkit 对象映射

ios - 为添加边框的 UIView 创建子类的步骤是什么?

swift - 在 Swift 中将 GMSMapView 分配给 UIView