2012-04-12 7 views
0

ich die Codes unten verwendet, um die MenüauswahlindexpostNotification die Funktion korrekt ausgelöst, aber userinfo (NSDictionary) hat nichts

NSDictionary *userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"123"] 
               forKey:@"Index"]; 
    [[NSNotificationCenter defaultCenter] postNotificationName: @"notifyToMenuSelectionNotification" 
                object: userInfo]; 



-(void)menuSelectionNotification:(NSNotification *)notification 
{ 
    NSLog(@"%@", notification.userInfo); 


} 

menuSelectionNotification ausgelöst wird richtig,

aber NSLog Ausgabe notification.userInfo ist

zu benachrichtigen noch {null}

begrüßen jede comment1

+0

Jetzt haben Sie drei doppelte Antworten haben - wählen Sie ein gelegentliches Ihr Problem zu lösen :) – tilo

Antwort

1

Sie übergeben Objekt auf falsche Weise. Bitte versuchen Sie dies -

NSDictionary *userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"123"] 
               forKey:@"Index"]; 

[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyToMenuSelectionNotification" 
             object:nil 
             userInfo:userInfo]; 
0

Sie haben Ihr Wörterbuch als userinfo Parameter zu setzen, nicht als die Objekt. Sie können versuchen

[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyToMenuSelectionNotification" object:nil userInfo:userInfo]; 
0

Sie sollten das Wörterbuch in userInfo Parameter veröffentlichen, zB

[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyToMenuSelectionNotification" object:nil userInfo:userInfo]; 

Für weitere Details, pl. finden Sie in der Dokumentation NSNotificationCenter

0

bitte versuchen Sie es mit diesen

[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyToMenuSelectionNotification" object:userInfo userInfo:nil]; 

-(void)menuSelectionNotification:(NSNotification *)notification{ 
NSDictionary *userInfo = (NSDictionary*)notification.object; 
} 
Verwandte Themen