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

标签 ios swift uitableview

我正在用数据填充 UITableView 并且工作正常。

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

tableView.tableFooterView = UIView()

tableView.tableFooterView = UIView(frame: CGRectZero)

截图:

enter image description here

但两者都只是删除了单元格边框,而不是出现的额外空白。 请建议。提前致谢。

编辑:

选择按钮不是单元格的一部分。只是试图点击选择按钮,然后 UITableView 显示在它下面。 (就像 DropDown 一样)。 此外,使用默认 Tableview Cell 而不是自定义 TableView Cell

代码:

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
    }

Storyboard截图

enter image description here

最佳答案

如果您不想要空单元格,请将 TableView 样式从 Plain 设置为 Grouped。

关于ios - 删除多余的单元格/行空格,而不会在 UITableView 上显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35556411/

相关文章:

ios - AlamofireImage 在缓存图像 v3.1 之前简要显示的占位符图像

ios - 由于 ipv6 网络问题,苹果拒绝了 phonegap ios 应用程序

swift - 使用 SceneKit 进行 hitTesting 不返回 SCNNode 的命中

ios - IBDesignable UI 未在带有 Swift 的 Xcode 9 中显示

swift - UIBarButtonItem 操作不工作 UITableView 单元格

使用来自不同开发帐户的不同证书签名的应用程序的 iOS 推送通知

ios - removeFromSuperview() 不工作

swift - Comparable 协议(protocol)可以通用吗?

ios - 通过两个 ViewController 传输数据

ios - 将按钮添加到 UITableView 单元格