When I call [tableView reloadData]
the function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Inspite of writing this [self.tableView reloadData];
try below, becuase already you have written class so no need to take the outlet again:-
[self reloadData]
This happened to me because there was a call to
tableView.beginUpdates()
without a call to
tableView.endUpdates()
In my code. Removing tableView.beginUpdates()
resolved the issue for me.
If you are not able to reload table using
[self.tableView reloadData];
Please make sure you are adding reference to following from the storyboard
@property (weak, nonatomic) IBOutlet TableView *tableView;
How to add reference you can click on following Image Link:
tableView reference outlet
I spent days debugging this issue, and found a ton of possible fixes. I starred the one that worked for me but they're all valid.
First, of course, check that your delegate, datasource, IBOutlet, etc are all configured properly.
**Set the All Exceptions breakpoint and see if you are getting an out of bounds exception in your datasource. Without setting the breakpoint there is no crash and the tableview will simply fail to reload.
Other possible fixes: check the tableview's frame to make sure the width or height is not 0. Try executing reloadData on the main thread. Lastly, try only reloading a single section (here).
Gotta love table views.
I was having the same issue, that the reload was not working. I believe the delegate method I was calling it from was in a background thread which was causing the problem. My solution was to create a new method (below) and call the reload from there instead, while also ensuring to call it from the main thread:
- (void) tocLoad {
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
It looks like you are never setting the delegate
and datasource
properties on your tableview, no? You're implementing the methods in those protocols inside tableview.m
but not setting the two properties to self
hence calling reloadData
having no effect.
Does this help?
Edit:
Looks like you have a tableView
property set on a subclass of UITableView
and hooked up to an interface builder file. This is an odd setup (a tableview within a tableview). Usually you would have something like a UIViewController
subclass hooked up to an XIB and set an
@property (nonatomic, strong) IBOutlet UITableView * tableView
in that subclass, or something similar. And then handle the data fetching and tableview delegate/datasource inside that viewcontroller subclass.
But here, because of the nested UITableView
s it's not as straightforward. Is there a reason for this design? I recommend moving to something like I describe above to help bring clarity to the setup.
Also, try adding some NSLog
statements into your init
method to see if the tableview != nil and the delegate and datasource properties have been set. My suspicion is that the connection is not being made.
Also, unrelated to the problem at hand, you no longer have to manually @synthesize ivar = _ivar
, it will be done for you automatically using the underscore convention.