我会从模型发送通知,告诉“某人”需要显示某些视图。
NSDictionary *userInfo = @{ @"TheViewKey": viewToDisplay];
[[NSNoticationCenter defaultCenter] postNotificationName:@"NotificationThatThisViewNeedsToBeDisplayed" object:self userInfo:userInfo];
然后委托(或活动视图控制器)将注册到此通知并处理显示。
// self is the delegate and/or the view controller that will receive the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleViewToDisplay:) name:@"NotificationThatThisViewNeedsToBeDisplayed" object:nil];
如果您放入视图控制器,请记住在视图不可见时从观察者中删除 self:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NotificationThatThisViewNeedsToBeDisplayed"];
通过这种方式,您的模型与演示文稿分离。