If the student does not come to class, the teacher sends a notice to the parents
1 #import "Parents.h"2 //#import "Teacher.h"3 @implementationParents4 5-(instancetype) init6 {7Self =[Super init];8 if(self) {9 //Registration NoticeTen //Addobserver: The Observer, where the notice is received, One //Selsctor: The method by which the response is notified, is a selector that specifies a method to receive the specified notification A //Name: The name of the response, which is the name of the notification, may be received only if it matches the notification name of the notification hub - //object: Pass parameter who goes to respond to an event when object is nil in addition to itself, all notifications named Isattenclass can receive notifications -[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (attendclass:) Name:@"Isattendclass" Object: nil]; the } - returnSelf ; - } - +- (void) Attendclass: (Nsnotification *) Notification - { + //Teacher *teacher = notification.object; ANSLog (@"Trigger Notification"); atNSLog (@"Hello parents,%@.", [notification UserInfo]); - } - - - -- (void) Dealloc in { - //remove a specified notification to[[Nsnotificationcenter Defaultcenter] removeobserver:self name:@"Isattendclass" Object: nil]; + - //Remove all Notifications the [[Nsnotificationcenter Defaultcenter] removeobserver:self]; * } $ Panax Notoginseng @end
1 #import<Foundation/Foundation.h>2 3 #import "Parents.h"4 5 @interfaceTeacher:nsobject6 7 @property (nonatomic,assign) BOOL Isattendclass;8 9- (void) postnotification;Ten One @end A - - the - - - + - + A #import "Teacher.h" at - @implementationTeacher - - -- (void) Postnotification - { inParents *parents =[[Parents alloc]init]; -_isattendclass =NO; to + //Send Notifications - //object: Send notification to who the if(!_isattendclass) { *[[Nsnotificationcenter Defaultcenter]postnotificationname:@"Isattendclass" Object:p arents userinfo:@{@"Notice":@"The kid didn't come to class."}]; $ }Panax Notoginseng } - the @end
Notice of Object-c