0

I want to populate data into a tableview from a web service call. But tableView numberOfRowsInSection executes before I get back my results from the web service call(which brings back data immediately) Here is my code:

- (void)viewDidLoad {
    [super viewDidLoad];
    routes = [[NSMutableArray alloc] init];
    [self loadDataWithStopName:@""];
    [self.tblview reloadData];

}

.h:

@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

as you can see, I even tried to reloadData on the tableview property, but it did not work.

Machavity
  • 30,841
  • 27
  • 92
  • 100
monkey man
  • 51
  • 1
  • 6
  • Reload the table after service call is done and result is success. You can post a notification after service call is done. Reload the table in the observer method of that notification. – Dev Aug 19 '15 at 13:18

1 Answers1

3

I guess that the call to your web service is asynchronous in loadDataWithStopName.
This means that reloadData will be called even if your web service call is not finished yet.
You have to make sure to call reloadData after the data is actually loaded. Like in the callback method of your web service call.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
  • thanks, that worked.. but now i am getting a different error, 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' - do you know why that is ? – monkey man Aug 19 '15 at 13:25
  • @monkeyman, you need to create a prototype cell in your story board. Drag a table view cell onto your table view in the storyboard and name it Cell. – Wyetro Aug 19 '15 at 13:26
  • This is a totally unrelated issue. Please see this: http://stackoverflow.com/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifierforindexpath – Quentin Hayot Aug 19 '15 at 13:27