在iOS中使用NSNotifcation传递字符串

时间:2015-11-02 23:33:29

标签: ios nsnotificationcenter nsnotifications swrevealviewcontroller

我很确定这个问题已经被问及并回答了,但我不确定我做错了什么我无法从NSNotificationCenter调用该方法。我有两节课: 类和日历视图类 我想将单用户凭证从SignIn传递到日历。我已将日历放在SWRevealController中。正在调用NSNotification,但由于某种原因未调用触发器方法。

登录

- (IBAction)signIn:(id)sender {

    _passWord = _password.text;
    NSLog(@"%@ %@",_userName,_passWord);
    [[NSNotificationCenter defaultCenter] postNotificationName: @"Password" object: _passWord];
   [self performSegueWithIdentifier:@"signIn" sender:self];

}

日历

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage *ppnImage = [UIImage imageNamed:@"PPNImage.png"];
    NSLog(@"came here");
    [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(triggerAction:) name:@"Password" object:nil];
    SWRevealViewController *revealViewController = self.revealViewController;
    if ( revealViewController )
    {
        [self.sidebarButton setTarget: self.revealViewController];
        [self.sidebarButton setAction: @selector( revealToggle: )];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
    events = [[NSMutableArray alloc]init];
    [_indicator startAnimating];
    self.tableView.delegate = self;
    //Creating a background queue
    web = [WebRequests sharedInstance];
    web.delegate = self;
    [web loginView];

}

-(void) triggerAction: (NSNotification *) notification {
    NSLog(@"Does not call this");
}

这里

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(triggerAction:) name:@"Password" object:nil]; 

被调用 但以下方法不称为

-(void) triggerAction: (NSNotification *) notification
 {
    NSLog(@"Does not call   this");
}

真的很感激,如果有人能告诉我我做错了什么

0 个答案:

没有答案