iOS: CBLUITableSource, two queries and one table with two sections

73 views
Skip to first unread message

Souhail Marghabi

unread,
Apr 8, 2015, 4:23:01 AM4/8/15
to mobile-c...@googlegroups.com
Hello Everyone,

I have two queries that should fill two sections in my uitableview. In the iOS couchbase examples, they add an object of time CBLUITableSource to which they assign one query.
For my case, how should I define my dataSource for the tableview driven by two couchebase queries? I have always defined the process by doing this in my view didload :

CBLQuery *query = [DRContacts queryContactsBy:self.currentOfferID error:&error];    

    if (_dataSource) {

        _dataSource.query = query.asLiveQuery;

        _dataSource.tableView = self.tableView;

       // _dataSource.tableView = self.contactsTableView;

    }

    

    CBLQueryEnumerator *rows = [query run:&error];


and in the couchebase table delegate: 

- (UITableViewCell *)couchTableSource:(CBLUITableSource *)source cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 DRContactsTableViewCell *cell = (DRContactsTableViewCell *)[source.tableView

                                                    dequeueReusableCellWithIdentifier:CellIdentifier

                                                    forIndexPath:indexPath];

    CBLQueryRow *row = [source rowAtIndex:indexPath.row];

//how to tell it that i have two queries from where i need to get the rows...

  DRContacts *contactCell = [DRContacts modelForDocument:row.document];

return cell;

   }

    

Thank you for your assistance in advance.

Martin Palatnik

unread,
Apr 8, 2015, 9:31:14 AM4/8/15
to mobile-c...@googlegroups.com
Hi, 
I think in this kind of cases is better to define your own datasource. You can check the source is on git. Then, just create your own based on the one there by modifying what you need. You can also subclass it but some stuff won't be as easy to modify by subclassing.

Cheers

Marghabi Souhail

unread,
Apr 8, 2015, 9:34:03 AM4/8/15
to mobile-c...@googlegroups.com
Hi,

Thanks for your suggestion.
 I was thinking maybe I won’t use the couchbase  table source and use my own. and have the output of the query stored in an nsarray that i would process in the tableview delegates and assign the data to each section in my tableview.


--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/L1p5QAhSkRI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/a3a0570f-3f71-42ed-9d74-53f3f156356c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages