Moin Ahmed
Moin Ahmed

Reputation: 2898

how to display the data in the Table view of IOS while using RestKit

I'm developing an app in IOS using RestKit. Data is retrieved successfully but i'm not able to display it in the Table view (i.e. rows are empty). when i scroll the table, rows are displayed correctly (i.e. data is there !!).

You will get the better idea from the code.(for just the simplicity, i provided the rough outline of the code, let me know if more code is needed.)

TableViewController.m

- (void)viewDidLoad
{   
    NSLog(@"viewDidLoad_inside!!");
    RKRequest* request = [[RKClient sharedClient] get:@"/urlstring" delegate:self];
    [request send];
    NSLog(@"request is sent");
    [super viewDidLoad];
} 

- (void)requestDidStartLoad:(RKRequest *)request {
       NSLog(@"request did start Load");
}

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
         NSLog(@"request didLoadResponse");
......
  //rest of the code Logic
...... 

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"table_inside!!");
}

code executes successfully but Table's rows are empty.!!

Output:

viewDidLoad_inside!!

request did start Load

request is sent

table_inside

request didLoadResponse

So the problem is, methods are not executing in proper order. why this is happening?. How to resolve it. is there any better approche to do so. I'm new to IOS so couldn't figured it out.

I tried Peter Kelly's answer and that works fine. But the tableView method must not be executed until the records are retrieved successfully. How to change the execution sequence.

Any help would be greatly appreciated.

Upvotes: 0

Views: 571

Answers (1)

Peter Kelly
Peter Kelly

Reputation: 14401

Have you reloaded your tableView after you have all the data?

[self.tableView reloadData];

Upvotes: 3

Related Questions