If I have two ViewControllers one which contains a UITableView and another which updates data in the tableView How to reload table data when I pop the ViewController?
I tried ViewWillAppear, ViewDidAppear. But It is not working. Exactly reloadData works but tableview is not changed
private var diaryList =
[[DiaryListJsonValue.DiaryListNew.Monthly]]()
private var expandedcells:[IndexPath] = [IndexPath]()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.section, indexPath.row)
let isContain = expandedcells.firstIndex(of: indexPath)
if (isContain == nil) {
expandedcells.append(indexPath)
}
else {
if let nContain = isContain {
expandedcells.remove(at: nContain)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if expandedcells.contains(indexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: DiaryListCells.identifier, for: indexPath) as! DiaryListCells
let list = diaryList[indexPath.section][indexPath.row]
self.diaryDate = list.diaryDate
return cell
else {
let cell = tableView.dequeueReusableCell(withIdentifier: DiaryListOffcell.identifier, for: indexPath) as! DiaryListOffcell
let list = diaryList[indexPath.section][indexPath.row]
...
return cell
this is tableview setting.
struct DiaryListJsonValue: Codable {
var diaryList: [DiaryListNew]?
enum CodingKeys: String, CodingKey {
case diaryList = "DiaryList"
}
struct DiaryListNew: Codable {
var isLast: Bool
var monthly: [Monthly]?
enum CodingKeys: String, CodingKey {
case isLast = "IsLast"
case monthly = "Monthly"
}
struct Monthly: Codable {
var diaryDate : String // yyyy-MM-dd
var recommendedCalorie : Int
var intakeCalories : Int
var intakeRate : Int
var mealIntakeCalories : [Int?]
enum CodingKeys: String, CodingKey {
case diaryDate = "DiaryDate"
case recommendedCalorie = "RecommendedCalorie"
case intakeCalories = "IntakeCalories"
case intakeRate = "IntakeRate"
case mealIntakeCalories = "MealIntakeCalories"
}
}
}
}
This is data struct
First viewDidLoad tableview.reloaddata works, also I have refresh function with tableview.reloaddata. It also works! but I performsegue nextView(data uplaod view), in the nextView uploaded data and popview. I expected tableview updated. But not updated.