У меня есть tabBarController, и на одной из вкладок я могу выбрать любой документ, который будет находиться на моей вкладке Избранное.
Поэтому, когда я перехожу на вкладку Избранное, должны отображаться избранные документы.
Я вызываю перезагрузку после извлечения из CoreData избранных документов:
override func viewWillAppear(_ animated: Bool) {
languageSelected = UserDefaults().string(forKey: "language")!
self.title = "favourites".localized(lang: languageSelected)
// Sets the search Bar in the navigationBar.
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.obscuresBackgroundDuringPresentation = false
search.searchBar.placeholder = "searchDocuments".localized(lang: languageSelected)
navigationItem.searchController = search
navigationItem.hidesSearchBarWhenScrolling = false
// Request the documents and reload the tableView.
fetchDocuments()
self.tableView.reloadData()
}
Функция fetchDocuments () выглядит следующим образом:
func fetchDocuments() {
print("fetchDocuments")
// We make the request to the context to get the documents we want.
do {
documentArray = try context.fetchMOs(requestedEntity, sortBy: requestedSortBy, predicate: requestedPredicate)
***print(documentArray) // To test it works ok.***
// Arrange the documentArray per year using the variable documentArrayPerSection.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy"
for yearSection in IndexSections.sharedInstance.allSections[0].sections {
let documentsFilteredPerYear = documentArray.filter { document -> Bool in
return yearSection == formatter.string(from: document.date!)
}
documentArrayPerSection.append(documentsFilteredPerYear)
}
} catch {
print("Error fetching data from context \(error)")
}
}
Из оператора print (documentArray) я вижучто функция обновляет контент.Однако в tableView нет перезагрузки документов.
Если я закрою приложение и снова открою его, оно обновится.
Не знаю, что я делаю неправильно !!!