Question

Started from scratch with a TVC and a core data tableview controller. I've implemented a pull to refresh in viewdidload. The thing is when i update core data using sqllite for example, the data is not updated, even if i call [self.tableView reloadData];

My MasterViewController.h:

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface MasterViewController : UITableViewController <NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;

@end

and my MasterViewController.m (from Apple template):

#import "MasterViewController.h"

@interface MasterViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end

@implementation MasterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
    self.navigationItem.rightBarButtonItem = addButton;

    // Initialize Refresh Control
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];

    // Configure Refresh Control
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

    // Configure View Controller
    [self setRefreshControl:refreshControl];
}

- (void)refresh:(id)sender {

    NSLog(@"Refreshing View ...");

    // End Refreshing
    [(UIRefreshControl *)sender endRefreshing];

    [self.tableView reloadData];

}

Thanks for help !!

Was it helpful?

Solution

I don't see any part of your code that updates your data.

The fact that you call "reloadData" on your UITableView won't fetch any new data, it will just call again the datasources protocols calls you implemented (numberOfSectionsInTableView, numberOfRowsInSection, cellForRowAtIndexPath, etc). So when the refresh control is pulled, fetch the new data, then call "reloadData".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top