Retrieving Backendless collection data in UITableView

I re-used some of the code snippets from your code gen projects in order to try and retrieve data from my Alerts table in Backendless and display the data in a UITableView. However, no data is populating my ViewTable even though there is data in the collection viewable when I run an NSLog. I can’t see where I am going wrong. It seems that the table code is correct since when I create a test array and use that as the data, it populates the table as expected. I’ve been trying to figure this out for the past couple of hours and it probably needs a next set of eyes on it. See my code below.


#import "BENewsAlertsTableViewController.h"
#import "Fall2013IOSAppAppDelegate.h"
#import "AppConstant.h"
#import "Alerts.h"


extern int iNotificationCounter;


@interface BENewsAlertsTableViewController ()


@end


@implementation BENewsAlertsTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.view.backgroundColor = [UIColor clearColor];
    
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"green"]];
    [tempImageView setFrame:self.tableView.frame];
    
    self.tableView.backgroundView = tempImageView;
    
    QueryOptions *queryOptions = [QueryOptions query];
    queryOptions.relationsDepth = @1;
    BackendlessDataQuery *dataQuery = [BackendlessDataQuery query];
    dataQuery.queryOptions = queryOptions;
    [backendless.persistenceService find:[Alerts class]
                               dataQuery:[BackendlessDataQuery query]
                                response:^(BackendlessCollection *collection){
             
                                    _collectiondata = collection.data;
                                    
                                    NSLog(@"List of items in collection.data: %@", collection.data);
                                    
                                }
                                   error:^(Fault *fault) {
                                   }];


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {


    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return _collectiondata.count;
    
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSObject *prop = [_collectiondata[indexPath.row] valueForKey:@"text"];
    NSLog(@"List of items in prop description in table: %@", [[prop description] stringByReplacingOccurrencesOfString:@"\n" withString:@" "]);
    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = [[prop description] stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
    cell.textLabel.font = [UIFont systemFontOfSize:14.0];
    cell.textLabel.numberOfLines = 4;
    return cell;
    
}








- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath

{

    

    if(indexPath.row % 2 == 0){

        UIColor *altCellColor = [UIColor colorWithRed:246/255.0 green:235/255.0 blue:253/255.0 alpha:1.0];

        cell.backgroundColor = altCellColor;

    }

    else{

        cell.backgroundColor = [UIColor whiteColor];

    }

}




-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    

    //[self refreshTable];

    //[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(refreshTable) userInfo:nil repeats:YES];

    

    //For reseting the tabbar badge value

    //Added by Maaj

    UITabBarController *tBar = (UITabBarController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];

    UITabBarItem *item=[[[tBar tabBar] items] objectAtIndex:1];

    [item setBadgeValue:nil];

    iNotificationCounter = 0;

    //----------------------------------------------//

    

}



@end

Please clarify:

  • is collectiondata a property (strong) of BENewsAlertsTableViewController calss?
  • did you see this log:
NSLog(@"List of items in collection.data: %@", collection.data);

You use an async method, so try to add ‘reloadData’ in line 37.

reloadData worked. Thanks!

Can you help me how to do this using swift?