[英]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都没有填充行时,它将显示一些多余的行为空。 如果您不希望这样做,那么您将有不同的可能性:
添加到@choli答案您可以做两件事,
tableView.tableFooterView = UIView(frame: CGRectZero) tableView.backgroundColor = UIColor.clearColor()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.