私のアプリでは、すべてのビューの背景色を暗く変更しました。しかし、tableViewから行を削除すると、行の背景が白に変わりました。なぜ、どうすれば修正できますか?tableViewから行を削除しているときにデフォルトの背景色を変更する
tableView.backgroundView?.backgroundColor = UIColor(red:0.1922, green:0.1922, blue:0.1922, alpha:1.0)
view.backgroundColor = UIColor(red:0.1922, green:0.1922, blue:0.1922, alpha:1.0)
if dataManagement.taskData.count != 0{
for rowIndex in 0...tableView.numberOfRows(inSection: 0) - 1 {
let cellPath = IndexPath(row: rowIndex, section: 0)
if let cell = tableView.cellForRow(at: cellPath) as? TaskListTableViewCell {
cell.backgroundColor = UIColor(red:0.1922, green:0.1922, blue:0.1922, alpha:1.0)
cell.taskLabel.textColor = UIColor.white
}
}
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { //可删除
let cell = tableView.dequeueReusableCell(withIdentifier: "taskCell", for: indexPath) as! TaskListTableViewCell
if editingStyle == UITableViewCellEditingStyle.delete {
if dataManagement.taskData[(indexPath as NSIndexPath).row].id == dataManagement.currentTask {
dataManagement.currentTask = nil
dataManagement.historyIsSelected = true
pomodoroTimer.stop()
}
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}
関連コードを表示してください。 – LinusGeffarth
テーブルを作成して行を削除するために使用したコードを表示します –
テーブルはUITableViewControllerにあります。私は自分のコードを追加しました。 @LinusGeffarth –