Giving notification to another class with NSNotificationCenter

前端 未结 2 1357
礼貌的吻别
礼貌的吻别 2021-01-14 06:19

So my goal is to deliver a notification to another class with using NSNotificationCenter, I also want to pass object with the notification to the o

2条回答
  •  不知归路
    2021-01-14 06:57

    Just call any method for posting notifications as described here, for instance :

    to post a notification :

    -(void)postNotificationName:(NSString *)notificationName
                         object:(id)notificationSender
                       userInfo:(NSDictionary *)userInfo;
    

    where userInfo is a dictionary containing useful objects.

    On the other side to register for notifications :

    -(void)addObserver:(id)notificationObserver
               selector:(SEL)notificationSelector
                   name:(NSString *)notificationName
                 object:(id)notificationSender;
    

    You could also check Apple's Notification Programming Topics.

提交回复
热议问题