Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created June 9, 2014 11:19
Show Gist options
  • Select an option

  • Save sideshowcoder/a18925f3f59b878bdd91 to your computer and use it in GitHub Desktop.

Select an option

Save sideshowcoder/a18925f3f59b878bdd91 to your computer and use it in GitHub Desktop.
Couchbase as a table view data source
class ItemsViewController < UIViewController
attr_accessor :database, :user_id, :data_source
def viewDidLoad
super
navigationItem.title = "Items"
@items_table = UITableView.alloc.initWithFrame(view.bounds)
@items_table.delegate = self
@data_source = CBLUITableSource.alloc.init
@data_source.query = Item.queryListsInDatabase(database).asLiveQuery
@data_source.labelProperty = "title"
@data_source.tableView = @items_table
@items_table.dataSource = @data_source
view.addSubview @items_table
end
def couchTableSource source, updateFromQuery:query, previousRows:previousRows
@items_table.reloadData
end
def couchTableSource source, willUseCell:cell, forRow:row
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment