Make pageViewController After NSURLSession is complete
<p>I'm a newbie on coding in objective-c.</p>

<p>I'm currently making an exercise application where I need to get some json-data from an API with a NSURLSession and send the date to a PageViewController.</p>

<p>So currently I'm getting my json-data in the method 'getWeer',which I call before making the pageViewController (in viewDidLoad). But because the NSURLSession runs async I think and isn't complete, the json-data always is null when I try to access it in my pageViewController.</p>

<p>How can I make the pageViewController after the NSURLSession is complete?</p>

<pre><code>@interface SecondViewController ()&lt;CLLocationManagerDelegate&gt;
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) NSString *AppId;
@property (nonatomic, weak) NSDictionary *json;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.AppId = @"feda1f13263bb730deeb89fb3936a76e";
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [[self locationManager] requestWhenInUseAuthorization];
    [[self locationManager] startUpdatingLocation];

    [self getWeer];


    // Create page view controller
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
    self.pageViewController.dataSource = self;

    PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    // Change the size of page view controller
    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);

    [self addChildViewController:_pageViewController];
    [self.view addSubview:_pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index{

    // Create a new view controller and pass suitable data.
    PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];

    pageContentViewController.pageIndex = index;
    NSLog(@"%@",self.json);
    pageContentViewController.json = self.json;

    return pageContentViewController;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{

    NSUInteger index = ((PageContentViewController*) viewController).pageIndex;

    if ((index == 0) || (index == NSNotFound)) {
        return nil;
    }

    index--;
    return [self viewControllerAtIndex:index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{

    NSUInteger index = ((PageContentViewController*) viewController).pageIndex;

    if (index == NSNotFound) {
        return nil;
    }

    index++;
    if (index == 3) {
        return nil;
    }
    return [self viewControllerAtIndex:index];
}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController{
    return 3;
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{
    return 0;
}

-(void)getWeer{
    NSString *dataUrl = [NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/forecast/daily?lat=%f&amp;lon=%f&amp;cnt=4&amp;&amp;APPID=%@&amp;units=metric&amp;lang=nl", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude, self.AppId];

    NSLog(@"%f",self.locationManager.location.coordinate.latitude);
    NSLog(@"%f",self.locationManager.location.coordinate.longitude);
    NSURL *url = [NSURL URLWithString:dataUrl];

    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        });
    }];
    [dataTask resume];
}

@end
</code></pre>