我有一個問題,這是長期處理iv從來沒有看到爲什麼。爲什麼「顯示」Segue更新UITableViewCells而不是reloadData()?
問題
我有一個UItableview並從Firebase中加載數據。當我從ViewController#1繼續「顯示」到ViewController#2(使用UITableView)時,Firebase數據被加載到單元格中。
每個小區具有UITableViewRowAction「刪除」基本上刪除火力地堡信息。但是當我按下按鈕時,它並沒有刪除Firebase信息,但沒有刪除單元格。爲了讓這個UITableView更新,我必須將show顯示回任何其他ViewController並返回到ViewController#2以供它更新。
**此方法僅如果有超過1的UITableViewCell在表
問題#2的更新 - 僅1 UITableViewCell的
現在,如果只有1 UITableViewCell的加載和我「刪除」了。 ...它永遠不會消失,除非我在ViewController#2中創建一個新的UITableViewCell。
我有什麼企圖?
self.tableView.endUpdates()
self.tableView.reloadData()
㈣硬是插reloadData()的任何地方我可以看看是否會重新載入數據,但它只是不會加載它!
let delete = UITableViewRowAction(style: .Default, title: "Delete", handler: { (action, indexPath) in
self.tableView.dataSource?.tableView?(
self.tableView,
commitEditingStyle: .Delete,
forRowAtIndexPath: indexPath
)
self.tableView.beginUpdates()
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 {
tableView.beginUpdates()
print("DELETED LOCAL RECORD")
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")
}
tableView.deleteRowsAtIndexPaths([NSArray arrayWithObject: indexPath], withRowAnimation: .Automatic) // SHOWS ERROR
self.tableView.endUpdates()
return
})
你是說數據被刪除之前添加beginUpdates和endUpdates後?另外deleteRowsAtIndexPaths給出錯誤。iv更新了上面的代碼!非常感謝你的幫助! – brkr
請參閱此示例。這是你應該如何做刪除行操作。 [鏈接](http://www.ioscreator.com/tutorials/delete-rows-table-view-ios8-swift) –