Question

I'm building an app that begins by loading a 'downloading' view controller which fetches an array of data through an API call. Once the data is returned, the app then hides this view controller's view, and loads a tab bar controller, which houses two navigation controllers.

The first view pushed onto the first navigation controller is a table view. It is in this table view that I need to display the data retrieved from the API call in the initial 'downloading' view controller.

Can somebody please explain to me how I would pass this data between the 'downloading' and table view controllers? Considering they do not know about each other.

An important note is that the data must be fetched before loading the tab bar controller, so it is not possible to simply fetch the data from within the table view controller that will be using it.

Was it helpful?

Solution

Your data is subordinate to the application, so the application delegate could keep the pointer to the data, then the two views could access it using [[UIApplication sharedApplication] delegate].

Another option would be to send a message with the data to the application delegate when the download is complete. I assume you're already doing something like this since you say the app hides the view controller's view, rather than the view controller hiding itself. Somehow it must know that the download is complete. So, in the download controller:

- (void) downloadFinished {
    [listener downloadFinished:data];
}

And in your application delegate (the listener from the previous snippet):

- (void) downloadFinished:(NSData *)data {
    CustomViewController *c = [[[CustomViewController alloc] initWithData:data] autorelease];
    [downloadView removeFromSuperview];
    [window addSubview:c.view];
}

Where your custom view controller deals with loading the NIB and holding the Data for access by the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top