Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSNotification未从调度异步内部激发_Ios - Fatal编程技术网

Ios NSNotification未从调度异步内部激发

Ios NSNotification未从调度异步内部激发,ios,Ios,我有以下代码: 在会话completionHandler中,我有一个dispatch_async,其中包含对NSNotificationCenter post通知方法的调用。但是通知从来没有被激发过任何想法 NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:[NSURL URLWithString:url] completionHandler:^(NSData *data, NSURL

我有以下代码:

在会话completionHandler中,我有一个dispatch_async,其中包含对NSNotificationCenter post通知方法的调用。但是通知从来没有被激发过任何想法

NSURLSession *session = [NSURLSession sharedSession];

[[session dataTaskWithURL:[NSURL URLWithString:url] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    // populating appDelegate.statusItems variable ///// 

   ....... 

    dispatch_async(dispatch_get_main_queue()
                   , ^{

                       [[NSNotificationCenter defaultCenter] postNotificationName:@"DataReceived" object:nil userInfo:@{@"StatusItems":appDelegate.statusItems}];

                        [self performSegueWithIdentifier:@"DashboardSegue" sender:nil];
                   });



}]resume];
在LoginViewController(代码在上面)中,我还为侦听器注册了通知,但从未调用它们:

    -(void) setupNotifications
    {
        ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

        [viewController registerNotifications];

    }


-(void) registerNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(populateList:) name:@"DataReceived" object:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

-(void) populateList:(NSNotification *) notification
{
    NSDictionary *dict = notification.userInfo;

    _statusItems =  [dict valueForKey:@"StatusItems"];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    });

}

是否调用registerNotifications方法?您是否必须使用[self registerNotifications]而不是[viewController registerNotifications]仪表板Segue类接收通知。可能会在创建此视图之前发送通知。