我是编程的新手,所以请尝试解释详细信息或示例。我正在构建一个使用couchbase-lite的应用程序,以在tableview中显示结果列表。我想在列表中发生任何更改,因此我需要使用实时查询和CBLUITableSource类。我下载了Grocery Sync App示例,但我不太清楚如何在tableview中显示实时查询的结果。我还在xcode中使用默认的主 - 详细信息模板,并在tableview中显示自定义单元格。
我的问题是如何在表格视图中显示实时查询的结果?我需要使用CBLUITableSource吗?这是我到目前为止所做的:
我的表数据结果:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: MatchCellTableViewCell = tableView.dequeueReusableCellWithIdentifier("matchcell", forIndexPath: indexPath) as! MatchCellTableViewCell
return cell
}
实时查询:
func initializeQuery() {
let query = database.viewNamed("matches").createQuery()
liveQuery = query.asLiveQuery()
liveQuery.addObserver(self, forKeyPath: "rows", options: nil, context: nil)
liveQuery.start()
}
谢谢!
答案 0 :(得分:1)
CBLUITableSource
是一种方便的API,可以更轻松地在iOS上使用实时查询和表格视图。
结帐this repo,了解如何使用CBLUITableSource
设置表格视图。
如果在查询结果发生变化时需要更多地控制UI更新,您可以像使用CBLLiveQuery
一样使用:)。