我正在尝试使用swift从sqlite表中删除数据并删除UITABLEVIEW CELL的内容。
下面显示的代码工作正常(没有错误)。但问题是,下次运行应用程序时,它会填充先前sql查询中的数据。
@IBAction func removeAllData(sender: AnyObject) {
//deleting the data from arrays responsible for updating the labels in UITableView Cell
self.endData.removeAll()
self.startData.removeAll()
self.driveData.removeAll()
//Deleting the table
let tripsDB = FMDatabase(path: recievedDatabasePath as String)
if tripsDB.open(){
let sqlQuery = "DELETE FROM trips"
let results : FMResultSet? = tripsDB.executeQuery(sqlQuery, withArgumentsInArray: nil)
print(tripsDB.lastErrorMessage())
} else {
print(tripsDB.lastErrorMessage())
}
tripsDB.close()
self.tableView.reloadData()
}
任何建议都会有所帮助。非常感谢。
更新
let filemgr = NSFileManager.defaultManager()
let dirPaths = filemgr.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
databasePath = dirPaths[0].URLByAppendingPathComponent("trips.db").path!
//sending the database contents to table view controller. here the recievedDatabasePath Variable is equal to the current database path mentioned in the first view controller
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "historySegue" {
let destinationViewController = segue.destinationViewController as! HistoryTableViewController
destinationViewController.recievedDatabasePath = databasePath
}
}