NSNotification问题 - 不调用函数

时间:2011-04-26 12:16:06

标签: iphone objective-c nsnotification

给我一​​些建议,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];

    ....

}

1 个答案:

答案 0 :(得分:0)

尝试这样[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noteDate:) name:@"notedaterelatednotification" object:nil]; 而不是[nc postNotificationName:@“connectDate”对象:self userInfo:dicDate];这一行......

我希望您了解以下内容

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