Database Reference
In-Depth Information
We also override the dealloc method to remove ourselves as an observer.
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now we need to write the persistentStoreUpdated: and persistentStoreChanged: methods.
-(void)persistentStoreUpdated:(NSNotification *)notification {
[self loadCloseFriends];
[self.tableView reloadData];
}
-(void)persistentStoreChanged:(NSNotificationCenter *)notification {
[self loadCloseFriends];
[self.tableView reloadData];
}
As you can see we are just reloading our _closeFriends array and reloading our table view. This
keeps the data we see fresh and removes the possibility that it might be stale.
We have one more change to make and that is in the CloseFriendDetailViewController.m file. In
this file we will override the viewWillAppear: and viewDidDisappear: methods.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(persistentStoreChanged:)
name:@"PERSISTENT_STORE_CHANGED" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(persistentStoreUpdated:)
name:@"PERSISTENT_STORE_UPDATED" object:nil];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
We use the viewWillAppear: and viewDidDisappear: methods in this instance because we only care
about these changes if the view is showing. We already know that if we are pushing to this view we
have a current valid object.
Now let's write these two methods and wrap up.
-(void)persistentStoreChanged:(NSNotification *)notification {
[_delegate detailViewControllerDidClose:self];
}
 
Search WWH ::




Custom Search