流行视图时如何重新加载数据?
如果我有两个viewControllers一个包含一个uitaiteView,而另一个则在表格视图中更新数据 当我弹出ViewController时,如何重新加载表数据?
我尝试了ViewWillAppear,ViewDidAppear。但这是行不通的。 恰好重新扎data工作,但没有更改表观视图,
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
这是TableView设置。
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"
}
}
}
}
这是数据结构
First ViewDidload tableview.reloddata Works,我也具有tableview.reloaddata的刷新功能。它也有效! 但是我在NextView上传的数据和PopView中执行了Sextegue NextView(数据UPLAOD视图)。我希望TableView已更新。但没有更新。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这也取决于演示样式。
请参阅: swift viewwillappear在忽略视图控制器
wwdc:
It depends on presentation style also.
Refer: Swift viewWillAppear not being called after dismissing view controller
WWDC: https://developer.apple.com/videos/play/wwdc2019/224/