Iphone postNotification正确触发函数,但userinfo(NSDictionary)没有任何内容

Iphone postNotification正确触发函数,但userinfo(NSDictionary)没有任何内容,iphone,Iphone,我使用下面的代码通知菜单选择索引 NSDictionary *userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"123"] forKey:@"Index"]; [[NSNotificationCenter defaultCenter] postNotificationName: @"noti

我使用下面的代码通知菜单选择索引

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



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


}
菜单选择通知已正确触发

但是NSLog output notification.userInfo仍然是{null}


欢迎任何评论1

您必须将词典设置为userInfo参数,而不是对象。你可能想试试

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

您必须将字典设置为userInfo参数,而不是对象。你可能想试试

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

您以错误的方式传递对象。请试试这个-

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

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

您以错误的方式传递对象。请试试这个-

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

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

您应该在userInfo参数中发布字典,如

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

有关更多详细信息,请参见文档

您应该在userInfo参数中发布字典,如

[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyToMenuSelectionNotification" object:nil userInfo:userInfo];
有关更多详细信息,请参阅文档,请尝试以下操作

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

-(void)menuSelectionNotification:(NSNotification *)notification{
NSDictionary *userInfo =   (NSDictionary*)notification.object;
}
请试试这个

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

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

现在你有三个重复答案-选择一个随机答案来解决你的问题:现在你有三个重复答案-选择一个随机答案来解决你的问题: