I have a problem which iv been dealing with for a long time just never got around to seeing why.
Problem
I have a UItableview and load data into it from Firebase. When I segue "show" from ViewController #1 to ViewController #2 (with the UITableView) the firebase data is loaded into the cells.
Each cell has a UITableViewRowAction "delete" which basically deletes the Firebase information. But when i press the button..it does delete the Firebase information but not the cell. In order for that UITableView to update I have to segue "show" back to any other ViewController and come back to ViewController #2 for it to update.
** This method only updates if there is more than 1 UITableViewCell in the table
Problem #2 - Only 1 UITableViewCell
Now if there is only 1 UITableViewCell loaded and I "delete" it....it never goes away unless I create a new UITableViewCell in ViewController #2.
What have i tried?
self.tableView.endUpdates()
self.tableView.reloadData()
Iv literally plugged reloadData() anywhere I could to see if would reload data but it just wont reload it!
let delete = UITableViewRowAction(style: .Default, title: "Delete", handler: { (action, indexPath) in
self.tableView.dataSource?.tableView?(
self.tableView,
commitEditingStyle: .Delete,
forRowAtIndexPath: indexPath
)
let uid = NSUserDefaults.standardUserDefaults().valueForKey("uid") as! String // uid
DataService.dataService.deleteAudio(uid, project: self.sharedRec.projectName, vocalString: self.sharedRec.audioString )
let currURL = self.sharedRec.audioString
let url = "(currURL).caf"
//Document Directory
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
// Full File to Delete Location
let fileURL = dirPath.stringByAppendingPathComponent(url)
// This is to print out all directory files
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
do {
print("DELETED LOCAL RECORD")
self.tableView.reloadData()
try NSFileManager.defaultManager().removeItemAtPath(fileURL)
print("file deleted (fileURL)")
let directoryContents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions())
print("PRINT LOCAL DIC(directoryContents)") // NOT WORKING
self.tableView.reloadData()
} catch {
print("error")
}
self.tableView.endUpdates()
retu
})
