如何修复"删除一行后出现黑色背景"



如果删除了一行,则tableView在单元格下方显示黑色区域,而tableView与单元格视图一样具有白色背景色。

看看这个:https://www.dropbox.com/s/55ssb73t0ngr9yj/screenshot.png?dl=0

删除一行(可以是其中的任何一行,不一定是最后一行)后,突然出现了黑色区域,尽管我没有更改tableView的任何约束或高度。此外,在tableView后面,除了背景也是白色的"self.view"之外,该区域中没有其他内容,在表视图前面,没有定位任何视图。(有一个视图,但它是屏幕的大小,所以它不能只在这个区域是黑色的。)

extension ApptDetailViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return appt.places.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ApptDetailCell", for: indexPath) as! ApptDetailCell
cell.placeNumLabel.text = "Place (indexPath.row + 1)"
cell.placeNameLabel.text = appt.places[indexPath.row]
return cell
}
}
extension ApptDetailViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let moveString = appt.places.remove(at: sourceIndexPath.row)
let moveBool = appt.reachedPlaces.remove(at: sourceIndexPath.row)
appt.places.insert(moveString, at: destinationIndexPath.row)
appt.reachedPlaces.insert(moveBool, at: destinationIndexPath.row)
print("appt.places: (appt.places)")
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// deletion occurred.
appt.places.remove(at: indexPath.row)
appt.reachedPlaces.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .right)
}
}
}

根据我们的评论讨论--您可以使用视图层次结构调试器调试UI。这有助于确定视图中的异常情况。

或者尝试更改表视图的背景颜色。

最新更新