モデルはデータのフェッチと解析を処理する必要があります。処理が完了すると、NSNotificationCenterを使用して新しいデータについてViewControllerに通知できます。
たとえば、次のように実行できます。
モデルでいくつかを定義MyModelDidFinishFetchingDataNotification
し、データのフェッチと解析が終了したらそれを呼び出します
次に、viewControllerを作成するときに、それをオブザーバーとしてモデル通知に追加します
- (id)init
{
self = [super init];
if (self) {
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMyModelDidFinishFetchingDataNotification:)
name:MyModelDidFinishFetchingDataNotification
object:nil];
}
return self;
}
viewDidLoadで、データをフェッチするようにモデルに指示します
- (void)viewDidLoad
{
[super viewDidLoad];
[self.myModel fetchNewDataFromServer];
}
新しいデータを処理するメソッドを実装します
- (void)handleMyModelDidFinishFetchingDataNotification:(NSNotification *)not
{
NSArray *newData = [[not userInfo] objectForKey:@"someNewData"];
// set the new data to the viewController data property
self.myData = newData
// update the UI
[self.tableView reloadData];
}