Как исправить «черный фон после удаления одной строки» - PullRequest
0 голосов
/ 09 января 2019

Если строка удалена, 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)
    }
}
}

Ответы [ 2 ]

0 голосов
/ 09 января 2019

Или попробуйте изменить цвет фона таблицы.

0 голосов
/ 09 января 2019

Согласно нашему обсуждению комментариев - вы можете отлаживать свой пользовательский интерфейс, используя отладчик представления heirarchy. Это помогает точно определить аномалии в ваших взглядах.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...