繁体   English   中英

删除多余的单元格/行空白,而UITableView上不显示数据

[英]Remove extra cells/rows whitespace without data appearing on UITableView

我用数据填充UITableView并且也可以正常工作。

但是我的问题是,当UITableView的数据行数较少时,它会正确显示包含数据的行,但会显示空白。 例如:如果tableview有1行要显示,则显示该行,然后在其下有空白,如空行。 我试过了

tableView.tableFooterView = UIView()

tableView.tableFooterView = UIView(frame: CGRectZero)

截图:

在此处输入图片说明

但是两者都只是删除了Cell边框,而没有出现多余的空白。 请提出建议。 提前致谢。

编辑:

选择按钮不是单元格的一部分。 只是尝试单击“选择”按钮,然后在其下显示UITableView。 (如DropDown)。 另外,使用默认的Tableview单元格而不是自定义TableView单元格

代码:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cityList.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cityCellIdentifier, forIndexPath: indexPath) as UITableViewCell

        let row = indexPath.row
        cell.textLabel?.text = self.cityList[row].cityEn
        print("CityName" + self.cityList[row].cityEn )

        return cell
    }

故事板ScreenShot

在此处输入图片说明

如果您不希望空单元格将TableView样式从“普通”设置为“分组”。

抱歉,我要评论,但是信誉不够:

这是tableView的大小,每当整个tableview都没有填充行时,它将显示一些多余的行为空。 如果您不希望这样做,那么您将有不同的可能性:

  • 您可以减小tableView的大小-例如单元格数* cellHeight
  • 您可以更改tableView的外观,因此它将是clearColor而不是白色,因此占位符单元格将不可见。

添加到@choli答案您可以做两件事,

  1. 根据行调整表格视图的高度,将UITableView的高度调整为仅适合总内容大小的高度
  2. 更简单的解决方案是清除表格背景颜色tableView.tableFooterView = UIView(frame: CGRectZero) tableView.backgroundColor = UIColor.clearColor()

暂无
暂无

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

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