tableView reloadData not working

前端 未结 6 1612
小鲜肉
小鲜肉 2021-01-17 07:45

When I call [tableView reloadData] the function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

相关标签:
6条回答
  • 2021-01-17 08:13

    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]
    
    0 讨论(0)
  • 2021-01-17 08:14

    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.

    0 讨论(0)
  • 2021-01-17 08:17

    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

    0 讨论(0)
  • 2021-01-17 08:18

    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.

    0 讨论(0)
  • 2021-01-17 08:19

    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];
        });
    }
    
    0 讨论(0)
  • 2021-01-17 08:36

    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 UITableViews 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.

    0 讨论(0)
提交回复
热议问题