I am trying to refresh a tableView using table.reloadData() in SWIFT 3. I managed to get this working some time ago but now it simply stopped working out of the blue. No errors, no warning, nothing.
override func viewWillAppear(_ animated: Bool)
{
print("MainVC > viewWillAppear")
super.viewWillAppear(animated)
initializeCollectionView()
}
func initializeCollectionView()
{
print("MainVC > initializeCollectionView")
projectsArray = []
getDocumentDirectoryContent()
if(projectsArray.count > 0)
{
print(projectsArray.count)
//For testing only - To make sure the array is not empty
for var i in 0..<projectsArray.count
{
print(projectsArray[i].project_name)
}
cvProjects.isHidden = false
ivMainVCPlaceholder.isHidden = true
}
else
{
cvProjects.isHidden = true
ivMainVCPlaceholder.isHidden = false
cvProjects.reloadData()
}
}
Every time the app starts it calls the it grabs the data from documentDirectory and fills in the projectsArray array with objects. This works just fine.
The initializeCollectionView is called in viewWillAppear because the tableView was also supposed to be refreshed when a child viewController is dismissed. It is also called on tap:
@IBAction func btnRefreshCollectionAction(_ sender: Any)
{
print("MainVC > btnRefreshCollectionAction")
initializeCollectionView()
}
The problem is now the table won't refresh neither when a child viewController is dismissed nor when I tap on btnRefreshCollectionAction.
However, the projectsArray array is not empty in initializeCollectionView.
My first thought was to blame the Xcode upgrade I performed right before I noticed this stopped working but usually if there is any problem after an upgrade there are warnings and/or errors.
Any ideas?
reloadDatawhenprojectsArray.countis 0.numberOfSections(in tableView:)and/ortableView(_ tableView:numberOfRowsInSection:);)