Я, должно быть, упускаю что-то простое здесь.У меня есть приложение с несколькими контроллерами представления, и я пытаюсь сбросить строки таблицы (в частности, cell.detailTextLabel?.text
), когда пользователь переходит обратно в другой контроллер представления
SummaryViewController
import UIKit
class SummaryViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if isMovingFromParentViewController{
allRecipeData.removeAll()
}
}
let summaryStatementArr = ["Cell One", "Cell Two", "Cell Three", "Cell Four"]
var allRecipeData = [recipeSettings.recipeTimeSet, recipeSettings.selectedStirTimeArr.joined(separator: ", "), recipeSettings.recipeTimeSet, recipeSettings.recipeTimeSet]
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell4", for: indexPath)
cell.textLabel?.text = summaryStatementArr[indexPath.row]
cell.detailTextLabel?.text = allRecipeData[indexPath.row] // I want to reset this from firstviewController
return(cell)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Элементы в allRecipeData объявлены в глобальной переменной с использованием struct recipeSettings{}
У меня есть другой контроллер представления, который связан с вышеупомянутым, называемым firstviewController
firstviewController
import UIKit
class firstViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Code here to reset tableview cells in SummaryViewController
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath:
IndexPath) {
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)
-> Int {
return 7
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell3", for:
indexPath)
cell.textLabel?.text = "Data"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Как мне сбросить / перезагрузить / очистить содержимое таблицы SummaryViewController из firstviewController.Я надеюсь, что это ясно.
Заранее спасибо