Когда пользователь щелкает ячейку в табличном представлении, он меняет цвет, но когда он обновляет приложение (например, выходит из системы и снова входит в систему или проводит пальцем по своему iPhone), ячейка возвращается к исходному цвету - возможно ли это? чтобы сделать так, что когда пользователь обновляет приложение, ячейки, по которым он щелкнул, остаются измененным цветом, чтобы показать, что оно было открыто?
UPDATE:
Код в контроллере вида
extension NotificationViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return notifications.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationTableViewCell", for: indexPath) as! NotificationTableViewCell
let notification = notifications[indexPath.row]
let user = users[indexPath.row]
cell.notification = notification
cell.user = user
cell.delegate = self
cell.backgroundColor = UIColor(red: 245, green: 245, blue: 245)
return cell
}
}
код в UITableViewCell
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
let cellBackground = UIView()
cellBackground.backgroundColor = UIColor(red: 245, green: 245, blue: 245)
UITableViewCell.appearance().selectedBackgroundView = cellBackground
}
}
UPDATE:
Фрагмент структуры базы JSON:
"notification" : {
"CjeP35ceAQZJuUPhm7U1eF3Yq4F3" : {
"-La5XJZV059J-fcbH4Px" : {
"from" : "Gmg1ojNoBiedFPRNSL4sBZz2gSx2",
"objectId" : "-La5XJYuWm6dLfGnte2h",
"timestamp" : 1552740338,
},
"-La6KbtcG7VIIk7JsBvT" : {
"from" : "Gmg1ojNoBiedFPRNSL4sBZz2gSx2",
"objectId" : "-La6KbtbAAAPjeo98dGe",
"timestamp" : 1552753786,
},
"FoFQDAGGX9hntBiBdXYCBHd8yas2" : {
"-La6Kb4DyACBRihJf4c1" : {
"from" : "Gmg1ojNoBiedFPRNSL4sBZz2gSx2",
"objectId" : "-La6Kb42zWtwcAVlubK7",
"timestamp" : 1552753783,
},