开发者

Fetching object details from NSNotification

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜