views:

596

answers:

1

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.

+1  A: 

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.

Ed Marty
I would prefer the second option to the first - usually Apple will recommend passing objects between controllers rather than arbitrarily accessing the application delegate.
Tim
Thanks for the reply. I'm pretty much doing the second method you mentioned already. My only dislike with the way it's implemented is that the data has to be passed from the downloader -> app delegate -> tab bar controller -> navigation controller -> table view controller .... it seemed a bit of a convoluted way of doing it.Thanks, I appreciate the help.
Harry