我注册在超类(UIViewController)中得到通知,如下所示:
超类.m
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(notification:)
name:@"Notification"
object:nil];
}
- (void)notification:(NSNotification *)notification {
// Do something for SuperClass with the notification
}
现在在子类(SuperClass.m 的子类)中,我也像这样监听相同的通知:
子类.m
- (void)notification:(NSNotification *)notification {
// Do something specific for SubClass with the notification
}
这是一种可接受的(代码方面)方式来处理在处理超类中的通知时具有一般行为以及在处理子类中的通知时具有更具体的行为吗?