0

I am working on an application which uses bump technology.I do have four tab in which one is a table view .I wrote this bump API in app delegate class so that when the application is open it should be able to transfer the data.Transfer function is working properly.But the problem is that I am inserting the data into sq-lite and the data from sqlite is displayed in one of the tab bar item view.So when the user selects this tab bar item and receives the data i would like to insert and also reload the view with the new changes.As told before insertion i working.But the problem is reloading the view.Can any one help me with this problem?

Saad
  • 8,857
  • 2
  • 41
  • 51
rahul raj
  • 597
  • 1
  • 4
  • 15

1 Answers1

0

You can perform insertion in background using NSOperation and post notification whenever you insert/edit a record. Add listener to the View controller where you are displaying data.

So whenever the controller receive the notification, it will call the method to reload data from database.

@implementation MyClass

- (void) dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

- (id) init
{
    self = [super init];
    if (!self) return nil;


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData:) name:@"COREDATA_OBJECT_EDITED" object:nil];

    return self;
}

- (void) reloadData:(NSNotification *) notification
{
    if ([[notification name] isEqualToString:@"COREDATA_OBJECT_EDITED"])
        {
            //load records from database and reload tableview
        }
}

@end





//Method where you are saving data objects in some other class

- (void) saveDataObject
{

    //Save Data object, if saved successfully then post notification to listener to reload the data
    // All instances of MyClass will be notified
    [[NSNotificationCenter defaultCenter] postNotificationName:@"COREDATA_OBJECT_EDITED" object:self];

}
Jitendra Singh
  • 2,103
  • 3
  • 17
  • 26