views:

22

answers:

2

Hi there

basically, I'm stuck ha. I have a page where a video gets downloaded. It has a UIProgressView bar in it.

When the user selects a row in the table view it calls VideoPage *page = [[VideoPage alloc] initWithVideoId:[indexPath row]] and then pushes that view controller onto the view stack. This page then starts the download, and in turn the progress view.

Now, if the user presses back on the navigation controller and goes back to the list of videos and then chooses the SAME row again it will init a new version of this page, meaning that the init of the page that is constantly updating the UIProgressView is lost forever.

Is there any way around this? I'm sorry if the question is vague. Basically if I have already init'd a view controller with videoId = 3 then I don't want to init another one, I want to just push the current one again, so that the UIProgressView is still showing.

Thanks for any help you can give me. :)

A: 

Check if your viewController (the one pushed) is nil or not before you push a new one.

if (viewController == nil) LoginViewController *viewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];

[self.navigationController pushViewController:viewController animated:YES];        [viewController release];
Jordan
+1  A: 

You can keep a reference to your view controllers and store them in a dictionary keyed by the row index or something, then whenever the row is clicked you can check if the key exist in the dictionary, if it does then you just get the value and repush that onto the stack, if it doesnt exist then create it and add it to the dictionary and push it on to the stack...

After reading your comment, sounds like you need to have some sort of download manager class that will handle your downloads in the background...My suggestion would be make some singleton class that manages downloads, this class should keep the state of each movie download that the user initiated, when its time to recreate the view controllers, you should check with the manager to see if a certain download has already been initiated, if it has, then use the data in the download manager to put your view controller in the expected state...

Daniel
I tried this - the problem is that if they go back further then that variable is lost when they come back through - lets say you're 3 views down the view stack and you init a view controller - then go back to the previous view this works. But then if you go back one more view, then back into the view again then that wont work. :(
Thomas Clayson
check out my edit..
Daniel
thats a good idea... :) how would i access that class though? Where would I create the instance of it? In the app delegate?
Thomas Clayson
The app delegate is an instance of a singleton, but you should probably make your own singleton class, http://numbergrinder.com/node/29 talks about implementing the pattern in objective-c, its pretty straight forward
Daniel