NSNotification 问题 - 未调用该函数
请给我一些建议。
是
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样
[[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(noteDate:) name:@"notedatelatednotification" object:nil];
而不是 [nc postNotificationName:@"connectDate" object:self userInfo:dicDate];这条线......
我希望你知道下面这行
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