Very simple use case: Let's say an iOS app displays a MovieListController
view (inside of a UINavigationController
) with a list of movies. When the user touches on one, the app pushes a MovieDetailController
onto the navigation stack (i.e. [[MovieDetailController alloc] initWithMovieId:(NSString *)
. In the MovieDetailController
's viewDidAppear:
method, it makes an HTTP call to retrieve details based on the movie ID passed into it.
The challenge is that the MovieDetailController
gets pushed onto the navigation stack right away, and for a second or two while the details haven't been retrieved, the view shows a bunch of blank fields, which is undesirable.
To get around this, I'm thinking of having the MovieListController
not push the MovieDetailController
onto the stack right away. Instead, it would put up a progress indicator (I'm using SVProgressHUD), then call MovieDetailController
's initWithMovieId:
method which would kick off the HTTP call. Then when the data is received, the MovieDetailController
would make a callback back to MovieListController
to remove the progress indicator and then push the MovieDetailController
onto the navigation stack.
Is there a better pattern for this type of scenario? Should I be considering having the MovieDetailController
push itself onto the navigation stack when it's ready?
Note: I have considered loading the detail view and putting up an activity indicator, but you'll still be able to see an 'empty view' behind it which looks a bit weird. I have also considered just having the MovieListController
retrieve the details itself but this seems to break the encapsulation model - the MovieListController
should just be concerned about listing movies, not about their details.
Any thoughts? This Movie stuff is just an example - looking for a general pattern here.
Personally I would take the following approach.
The reason I would go this route rather than showing the HUD before pushing the view controller is that you can give the user the opportunity to cancel their selection. I am not familiar with SVProgressHUD
but hopefully when a HUD is displayed you can enable touches, specifically the user touching Back on your UINavigationController
in the event they accidentally selected the movie or the request is just taking longer than they are willing to wait for.
It also separates the logic form your list view, your detail view is standalone and could be initialized anywhere in your app (maybe you want to cross link similar movies within a movie detail view) and you do not need to rewrite the logic of the presenting view waiting on the results to come back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With