I have two view controllers: LocationsViewController
, and SettingsViewController
. LocationsViewController
conforms to the SettingsViewControllerDelegate
protocol. That protocol contains only 1 method:
// SettingsViewControllerDelegate.h
- (void)settingsViewControllerDidFinish:(SettingsViewController *)controller;
When my LocationsViewController
receives that delegate messages, it dismisses the SettingsViewController
that was presented modally.
I think this is good code design so far. The problem is the sharing of data between these view controllers. Both view controllers present the same data: an array of about 10 objects (locations). Only the SettingsViewController
allows altering of that array.
Right now I have 'solved' this in an inelegant way: both view controllers have a reference to my app delegate, and my app delegate has a locations
property. SettingsViewController
alters that array directly. For example:
// SettingsViewController.m
[appDelegate.locations addObject:newLocation];
It works, but I'm not happy with it. I understand it's a bad thing to just let your view controllers keep a reference to the app delegate. Any suggestions?