Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从NSNotification获取对象详细信息_Iphone - Fatal编程技术网

Iphone 从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

如何从NSNotification对象获取对象?有什么线索吗?

很简单。使用NSNotification的对象方法

- (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];

}