NSNotification проблема - не вызывая функцию - PullRequest
0 голосов
/ 26 апреля 2011

дайте мне совет, плз.

Am

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 голосов
/ 26 апреля 2011

Попробуйте вот так [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noteDate:) name:@"notedaterelatednotification" object:nil]; вместо [nc postNotificationName: @ "connectDate" object: self userInfo: dicDate];эта строка ....

Я надеюсь, что вы знаете, с приведенной ниже строкой

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