0

i'm using core data in my app, but i notice that is a bit slow and i have some crash of problems of inconsistency, maybe i have bad managed it, however i want pass to SQLite and i found the FMDB library, but my question is how i can automatically update a tableview when i made background change in the database? using the core data there is the NSFetchedController and in particular there is the NSFetchedResultsControllerDelegate to automatic refresh the table view, how i can perform this using the SQLite?

Piero
  • 9,173
  • 18
  • 90
  • 160
  • After change in DB call `[tableView relodData];`. Or you are making changes in DB outside of app? – Dilip Manek Apr 12 '13 at 11:33
  • No i make the call in a background thread in the app... – Piero Apr 12 '13 at 11:39
  • then create Notification. Which will fire when background thread complete and in that Notification method call `[tableView relodData];` to reload data in tableView – Dilip Manek Apr 12 '13 at 11:42

1 Answers1

3

You can use NSNotificationCenter for that, Here is the code sample..

In your TableViewController.m file add this code

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView:) name:@"ReloadTableView" object:nil];
    }
    return self;
}

- (void)reloadTableView:(NSNotification*)notification
{
    [tableView relodData];
}

And where you call your background thread, put this code in its completion.

[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadTableView" object:nil];
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56