NSNotificationCenter方法中的NSNotification参数为nil

时间:2015-04-13 15:08:27

标签: ios objective-c nsnotificationcenter nsnotification

NSNotification方法确实存在这个无法解释的问题。

我长期使用NSNotificationCenter但我无法解释为什么会这样。

我的问题是这个,

我有一个UITableViewCell子类,当用户点击单元格中的按钮时,我会向NSNotificationCenter发送UIViewController方法。

[[NSNotificationCenter defaultCenter] postNotificationName:MOVE_TO_PROGRAM_VIEW
                                                    object:self
                                                  userInfo:@{INDEX_ROW : [NSNumber numberWithInteger:self.tag]}];

self.tag是行(对于控制器中的数据模型)。​​

在控制器中,我在viewWillAppear:中注册通知,如下所示:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userWantsToGoToProgramView:) name:MOVE_TO_PROGRAM_VIEW object:nil];

我也在viewWillDisappear:

中删除了自己
[[NSNotificationCenter defaultCenter] removeObserver:self name:MOVE_TO_PROGRAM_VIEW object:nil];

现在在通知的方法中我尝试获取userInfo和行,但由于某种原因notificaiton参数为零..

- (void)userWantsToGoToProgramView:(NSNotification *)notification
{
    // notification is nil here


    // get the index of the video in the feed
    NSDictionary *userInfo = notification.userInfo;
    NSInteger videoIndex = [userInfo[INDEX_ROW] integerValue];
    NSDictionary *videoData = self.feed[videoIndex];

}

任何帮助建议都将受到赞赏

谢谢!

0 个答案:

没有答案