繁体   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