簡體   English   中英

如何從Swift XCode中的sqlite數據庫文件(citylist.db)中檢索Tableview或Textfield(自動完成)中的數據

[英]How To Retrive Data In Tableview or Textfield(autocomplete) from a sqlite DataBase file ( citylist.db ) in swift xcode

從過去的兩天開始,我正在Internet上搜索swift和sqlite之間的鏈接,但是我無法獲取它的代碼以及數據庫連接,因為我想從citylist.db文件中檢索數據到自動完成的文本字段中迅速。

如果有人知道代碼或對他們最歡迎的主題提出任何建議,請大家。

我通過該鏈接進行了另一件事https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md但卡在sqlcipher部分,現在我不知道該怎么辦?

這是在表視圖中使用sqlite顯示數據的示例代碼

 var db : Database!
var cat = Expression<String>("ZCATEGORY")
var name = Expression<String>("ZNAME")
var user : Query!
var stmt : Query!

//@IBOutlet var tabe: UITableView!
override func viewDidLoad() {
    super.viewDidLoad()
    createdb()
}



internal func createdb()
{
    let path = NSBundle.mainBundle().pathForResource("db", ofType: "sqlite")
    println(path)
    db = Database(path, readonly: true)
    user = db["ZFOOD"]
    println(db)
    stmt = user.select(distinct : cat)

}


func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var data = Array(stmt)
    return data.count

}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var data = Array(stmt)
    let cell: AnyObject = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
    cell.textLabel.text = data[indexPath.row][cat]
    return cell as UITableViewCell
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM