NSNotification 问题 - 未调用该函数

发布于 2024-11-03 12:57:37 字数 1084 浏览 0 评论 0原文

请给我一些建议。

NSDate *todayDate = [NSDate date];

NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
        [dateFormat setDateFormat:@"yy-MM-dd"];
        todayString = [dateFormat stringFromDate:todayDate];
        NSLog(@"today : %@", todayString);



NSDictionary *dicDate = [NSDictionary dictionaryWithObject:todayDate forKey:@"keyDate"];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"connectDate" object:self userInfo:dicDate];



B.m

- (void)noteDate:(NSNotification *)date {

    NSLog(@"notification");
    NSDate *startDate = [[date userInfo] objectForKey:@"keyDate"];

    stampDate = [[[NSDate alloc]init]retain];

    NSLog(@"savedDate : %@", startDate);
    self.stampDate = startDate;

    NSLog(@"notification date : %@", stampDate);


}



- (void)viewDidLoad {

    [super viewDidLoad];

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(noteDate:) name:@"connectDate" object:nil];

    ....

}

give me some advice, plz.

A.m

NSDate *todayDate = [NSDate date];

NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
        [dateFormat setDateFormat:@"yy-MM-dd"];
        todayString = [dateFormat stringFromDate:todayDate];
        NSLog(@"today : %@", todayString);



NSDictionary *dicDate = [NSDictionary dictionaryWithObject:todayDate forKey:@"keyDate"];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"connectDate" object:self userInfo:dicDate];



B.m

- (void)noteDate:(NSNotification *)date {

    NSLog(@"notification");
    NSDate *startDate = [[date userInfo] objectForKey:@"keyDate"];

    stampDate = [[[NSDate alloc]init]retain];

    NSLog(@"savedDate : %@", startDate);
    self.stampDate = startDate;

    NSLog(@"notification date : %@", stampDate);


}



- (void)viewDidLoad {

    [super viewDidLoad];

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(noteDate:) name:@"connectDate" object:nil];

    ....

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2024-11-10 12:57:37

尝试这样 [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(noteDate:) name:@"notedatelatednotification" object:nil];

而不是 [nc postNotificationName:@"connectDate" object:self userInfo:dicDate];这条线......

我希望你知道下面这行

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

Try like this [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noteDate:) name:@"notedaterelatednotification" object:nil];

instead of [nc postNotificationName:@"connectDate" object:self userInfo:dicDate]; this line....

i hope you aware with the below line

    [[NSNotificationCenter defaultCenter] postNotificationName:@"notedaterelatednotification" object:nil userInfo:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文