简体   繁体   English

如何使表格视图迅速实用地填充整个视图

[英]How to make a table view fill entire view pragmatically in swift

I am trying to make a UITable View fill the entire view with the options I supply. 我试图使UITable视图使用我提供的选项填充整个视图。 As of now I have four options. 截至目前,我有四个选择。 This is the code I am running: 这是我正在运行的代码:

func tableView(tableView: UITableView,
    heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.row == 1 {
            return (screensize.height-70)/4 //Whatever fits your need for that cell
        } else {
            return (screensize.height-70)/4 // other cell height
        }
}

The 70 comes from the navigation bar I have at the top of my page which takes 70 pixels. 70来自我位于页面顶部的导航栏,它占用70像素。 My problem is that no matter what I get some sort of white space buffer at the bottom of the simulator. 我的问题是,无论我在模拟器的底部获得了什么样的空白缓冲区。 Even with hard coded values I don't seem to be able to fill the display. 即使使用硬编码的值,我似乎也无法填充显示。 It will display the first 3 options and then you'll have to scroll for the fourth. 它将显示前三个选项,然后您必须滚动到第四个选项。 Please help. 请帮忙。

UPDATE: To set the table dimensions I used: 更新:设置我使用的表尺寸:

tableView.frame = CGRectMake(0, 71, screenSize.height-70, screenSize.width); tableView.frame = CGRectMake(0,71,screenSize.height-70,screenSize.width);

Try these to get your screen width and height 尝试这些以获取screen宽度和height

let width = UIScreen.mainScreen().bounds.size.width
let height = UIScreen.mainScreen().bounds.size.height

And then use these values fill your view with the scrollView or any other view if you need. 然后使用这些值将所需的scrollView view或其他任何view填充到view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM