2010-10-02 68 views

回答

3

當你發佈你可以在一個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]; 

} 
+0

謝謝你這麼多先生 – Abhinav 2010-10-03 02:25:54

2

非常簡單。使用NSNotification的對象方法。

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