0

我是编程新手,所以请尝试用细节或例子来解释。我正在构建一个使用 couchbase-lite 在 tableview 中显示结果列表的应用程序。我想在列表中显示任何更改,因此我需要使用实时查询和 CBLUITableSource 类。我下载了Grocery Sync App示例,但我不太明白实时查询的结果如何在 tableview 中显示。我还在 xcode 中使用默认的主从模板并在表格视图中显示自定义单元格。

我的问题是如何在表格视图中显示实时查询的结果?我需要使用 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()
}

谢谢!

4

1 回答 1

1

CBLUITableSource是一个方便的 api,可以更轻松地在 iOS 上使用实时查询和表视图。

查看此 repo以了解如何使用CBLUITableSource.

如果您需要在查询结果更改时对 UI 更新进行更多控制,您可以使用CBLLiveQuery您所做的 :)。

于 2015-05-14T19:40:17.877 回答