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
}
精彩评论