Hooking up UITableView to CBLUITableSource


I’m borrowing code from the Grocery Sync example, and having trouble hooking up a UITableView to the CBLUITableSource.

I notice in the demo project there is a Table Source object visible in the RootViewController.xib which connects the Table View with the dataSource. My app is being built without storyboards and I can’t work out how to replicate this in my project. So I’ve attempted to do this in my viewDidLoad method (see below).

Anything I might have missed here?

- (void)viewDidLoad {
    [super viewDidLoad];
    [tableView setDelegate:self];
    if (database) {
#pragma mark Create database query
        CBLLiveQuery* query = [[database createAllDocumentsQuery] asLiveQuery];
        // Plug the query into the CBLUITableSource
#pragma mark Configure table view for query
        dataSource.query = query;
        [dataSource setTableView: tableView]; // Are these needed? 
        [tableView setDataSource:dataSource];


In other words you’re building your UI in code instead of using a xib or storyboard?

Did you remember to instantiate dataSource, since you don’t have a xib/storyboard creating it for you?


Thanks, yes I am building the UI partly in code, although I still have an xib for the ViewController. The reason for this is I dont have the usual app delegate, I am instantiating via Objective-C++ linked to my C++ code (written with the JUCE framework).

I am learning Objective-C and iOS app development in order to build the UI for my app, as well as integrate Couchbase Lite, so please forgive me if my questions are a bit noobish.

As you suggested I had not initialized the dataSource instance. I now have something like:

    dataSource = [[CBLUITableSource alloc] init];
    dataSource.tableView = tableView;

However I’m still have issues getting the data to populate in the tableView.

I have a question regarding the CBLUITableDelegate: I had exceptions occuring due to missing UITableViewDelegate methods numberOfRowsInSection and cellForRowAtIndexPath. I’m not sure why these came up as the example code does not implement these methods. In my view controller xib I have dataSource and delegate outlets pointing to “File’s Owner”, and the same for the tableView referencing outlet.

I’ve not been able to work out how to recreate the “Table Source” CBLUITableSource object (solid cube) that exists in the demo project. This seems to be the way things are hooked up in the demo. I’m happy to do this in code too if there’s way.


You find the “Object” control in the interface builder class browser, which looks like that yellow cube, and drag it into the interface. Then while it’s selected you bring up the Identity inspector (in the right sidebar) and change its class to CBLUITableSource.


Great thanks, that also fixed the missing UITableViewDelegate methods.