ios - 如何让 uitableview 填满我所有的 View ?

标签 ios swift uitableview

我是 iOS 的新手。谁能告诉我如何解决这个问题,用 UITableView 填充我的所有 View :

Check Image

我正在尝试使用自动布局和约束来做到这一点,但我不知道为什么不起作用。

最佳答案

您要做的是让单元格高度相等,以便所有单元格一起正好适合屏幕的高度。

您不能使用自动布局来做到这一点。您必须像这样告诉 TableView 您希望行具有的高度:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    let heightOfVisibleTableViewArea = view.bounds.height - topLayoutGuide.length - bottomLayoutGuide.length
    let numberOfRows = tableView.numberOfRowsInSection(0)

    tableView.rowHeight = heightOfVisibleTableViewArea / CGFloat(numberOfRows)
}

请注意,此代码假定您实现方法tableView(_:heightForRowAtIndexPath:)

关于ios - 如何让 uitableview 填满我所有的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34161016/

相关文章:

iphone - 如何在不使用 Gamekit、EAaccessory 和 iOS 核心蓝牙框架的情况下发现另一个设备?

ios - 带有自定义单元格类的 UITableView 显示正确的行数但全部为空白

ios - 我的单元格正在复制以应用我对在线数据库所做的更改

ios - 我怎么能不使用原型(prototype)单元标识符重用单元 BUT

ios - 如何测试 Apple Push Notifications 反馈服务?

ios - 我的应用程序在 Xcode 7 中的主屏幕消失了

ios - 通过 NSBundle 访问声音文件 - pathForResource

ios - 对于 UITableViewCell 内的嵌套 UITableView didSelectRowAt indexPath : is not being called

ios - 将 UITableViewCell 加载到 xib 文件中的 UITableView

iphone - 如何将segue ios5 Storyboard uitableview中的数据传递到详细 View