Reputation: 757
About to pull my hair on this one.
My tableview stopped loading the data all of a sudden.
I have breakpoints in numberOfRowsInSection
and cellForRowAtIndexPath
. numberOfRowsInSection
which goes like
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [objects count];
}
gets called thrice, for some reason, when the view initially loads with the number of objects in the objects
array being 0 which can be understood because the tableview doesn't have any data initially.
After I fetch data from the server and store those objects in my objects
array and call [self.tableView reloadData];
, numberOfRowsInSection
gets called again with the number of objects in objects
array this time being 46 but it still doesn't go ahead and enter cellForRowAtIndexPath
for some reason.
I have tried reloading the data on the main thread -
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
No use.
I have checked all my spellings.
Checked that my UITableView
object is not nil when I am reloading the data.
The frame of the table view is 320.0000*568.0000 in viewDidLoad
.
No idea what's going wrong. And I am assuming I broke something because the data was loading just fine earlier.
Upvotes: 0
Views: 88
Reputation: 11
I am assuming that you are loading the view from another view, then you should call [tableView reloadData] on ViewDidLoad also update dataSource array there. This is because of the view life cycle - when you are coming back from one view and your tableView data source is updated, the view life cycle will be like this:
So when you update tableView's data source object and call reloadData during viewDidLoad will resolve the issue.
Upvotes: 1
Reputation: 757
[self.tableView beginUpdates];
I have no idea when and why I added this and then forgot to call endUpdates
. Sigh.
Thanks community. Huge help!
Upvotes: 0