Here's the question:
Is it possible for one view controller to add another view controller as an observer to the default center before loading the second view?
I have a model class that creates NSURLSession, captures some data, builds an array, and sends the notifications it made (along with a pointer to the array).
My applications are loaded using Map View, which creates an instance of the model, calls a method to create an array, listens for a notification, and drops contacts using the array.
I have a table tab that I want to load using an array built on a map.
Can my map view add my table observer as an observer before loading the table?
Sort of:
[[NSNotificationCenter defaultCenter] addObserver: TableViewController ...
Thank you for understanding. I understand this when I go.
----------------- EDIT --------------------
viewDidLoad from MapViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.delegate = self;
_model = [[WikiModel alloc] init];
_lastArticleUpdateLocation = [[CLLocation alloc] initWithLatitude:0 longitude:0];
_lastUpdateUserLocation = [[CLLocation alloc] initWithLatitude:0 longitude:0];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadData:)
name:@"Array Complete"
object:_model];
UITableViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"tableViewController"];
[[NSNotificationCenter defaultCenter] addObserver:tvc
selector: @selector(updateDataSource:)
name:@"Array Complete"
object:nil];
[self.navigationController pushViewController:tvc animated:YES];
}
From TableViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)updateDataSource:(NSNotification *)notification
{
_wikiEntries = [[notification userInfo] objectForKey:@"wikiEntryArray"];
[self.tableView reloadData];
NSLog(@"************received***********");
}
source
share