开发者

Fetching object details from NSNotification

开发者 https://www.devze.com 2023-01-18 16:31 出处:网络
How can I fetch开发者_Python百科 object from NSNotification object? Any clue?When you post you can wrap many objects in an NSDictionary.

How can I fetch开发者_Python百科 object from NSNotification object? Any clue?


When you post you can wrap many objects in an NSDictionary.

NSDictionary *userInfo=[NSDictionary withObjectsAndKeys:obj1,key1,obj2,key2,nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTI_NAME" 
                                                    object:self
                                                  userInfo:userInfo];

In you observer:

-(void)notiObserver:(NSNotification *)notification{

    NSDictionary *userInfo=[notification userInfo];
    OBJ1 *obj1=[userInfo objectForKey:key1];

}


Quite simple. Use the object method of NSNotification.

- (void)myMethod:(NSNotification* notification) {
    // Example with a NSArray
    NSArray* myArray = (NSArray*)[notification object];
    // Do stuff
}
0

精彩评论

暂无评论...
验证码 换一张
取 消