Some learning of Objective-c 2 Notification

defaultCenter, there is only one message center, and its singleton is obtained through the class method.
addObserver, add a listener instance, here is the current instance
selector, a method pointer in the observer, this method will be executed when there is a message, and the relevant context will be passed as a parameter
name, register the name of the message of interest,
object, This is a filter for the sender of the message. This parameter data indicates that the current listener is only interested in messages sent by a certain object.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshDocListNotification:) name:@"refreshDocListNotification" object:nil];


Push message :
postNotificationName, the name of the push message, matching the message name when registering the message listener.
object, the instance
userInfo of the sent message, the message context attached when sending the message, this instance is a dictionary instance (equivalent to HashMap in Java).
    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDocListNotification" object:self.docTempList userInfo:@{@"name":@"consultationChoose"} ];



When a message is pushed to the message center, the message will be sent to the relevant "listener", and the method of message registration will be executed:
-(void)refreshDocListNotification:(NSNotification*)notification{
    self.isPropose = NO;
    NSMutableArray *docTemplist = (NSMutableArray *)notification.object;
    [self.docList removeAllObjects];

    [self.docList addObjectsFromArray:docTemplist];
    [self completeDocListDataSource];
    [self.tableView reloadData];
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326897383&siteId=291194637