Iphone 从NSNotification获取对象详细信息
如何从NSNotification对象获取对象?有什么线索吗?很简单。使用NSNotification的对象方法Iphone 从NSNotification获取对象详细信息,iphone,Iphone,如何从NSNotification对象获取对象?有什么线索吗?很简单。使用NSNotification的对象方法 - (void)myMethod:(NSNotification* notification) { // Example with a NSArray NSArray* myArray = (NSArray*)[notification object]; // Do stuff } 很简单。使用NSNotification的对象方法 - (void)myMe
- (void)myMethod:(NSNotification* notification) {
// Example with a NSArray
NSArray* myArray = (NSArray*)[notification object];
// Do stuff
}
很简单。使用NSNotification的对象方法
- (void)myMethod:(NSNotification* notification) {
// Example with a NSArray
NSArray* myArray = (NSArray*)[notification object];
// Do stuff
}
发布时,可以在NSDictionary中包装许多对象
NSDictionary *userInfo=[NSDictionary withObjectsAndKeys:obj1,key1,obj2,key2,nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTI_NAME"
object:self
userInfo:userInfo];
在你看来,观察员:
-(void)notiObserver:(NSNotification *)notification{
NSDictionary *userInfo=[notification userInfo];
OBJ1 *obj1=[userInfo objectForKey:key1];
}
发布时,可以在NSDictionary中包装许多对象
NSDictionary *userInfo=[NSDictionary withObjectsAndKeys:obj1,key1,obj2,key2,nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTI_NAME"
object:self
userInfo:userInfo];
在你看来,观察员:
-(void)notiObserver:(NSNotification *)notification{
NSDictionary *userInfo=[notification userInfo];
OBJ1 *obj1=[userInfo objectForKey:key1];
}