views:

52

answers:

1

In my iPhone application, a user selects an item from a UITableView to choose a resource to view. The UIViewController subclass required to handle the resource is not known until the resource is retrieved, which may take a few seconds.

In response to the selection action, I push a "loading" view controller on the nav stack. That controller presents a view with a UIActivityIndicatorView along with (possibly) other status information, and initiates the download of the selected resource. From this view, the user might cancel the download, in which case I would return to the list of resources. If the resource arrives, though, an appropriate new view controller is created corresponding to its type.

Here's where it gets sticky. If I push the new type-specific view on the nav stack, the "loading" view is still in the stack; obviously once the loading is complete, there's no need to "go back" to that view. I've tried simply adding the type-specific view as a subview of the "loading" view, but that doesn't get my type-specific controller onto the nav stack, so it doesn't have a [self navigationController] for further navigation.

How can I "replace" the current view on the nav stack with a new one? Or, more generally, how can I show activity / progress when I don't yet know what controller will be used to display the resource being retrieved?

I've found pretty cool "HUD" progress indicator classes, but I don't want the progress indication to appear on top of the list of items being selected from. Instead, I want the user to perceive that they have "gone" to a new space that is waiting to be filled in.

I'm pretty new at this stuff, so I hope I've at least worded the question coherently. Thanks for any help anyone can provide.

+1  A: 

Update: Actually, it would probably be better to display your "loading" view as a modal view. Check out this question for a few examples.

You should pop the "loading" view controller and push the "specific" view controller once the latter has been downloaded and allocated. Play around with NOT animating one or both of those actions to see what gives the best experience.

gerry3
I'll give that a try, too... seems cleaner than my approach, but I'm wondering if there'll be any visual "noise" in the transition.
jgarbers
I'll look more into modal view controllers, but it doesn't seem like they'd work since I do not know what kind of controller I need to create until AFTER the transfer is complete. I'm using your pop/push approach successfully now, but I did have to be careful... [self navigationController] is nil after the current view is popped, so I had to put the nav controller in a temp variable long enough to do the two operations. Thanks!
jgarbers
I was thinking that the "loading" view would be presented as a modal view (not the "specific" view that you had to download data for).
gerry3
Yes... but then what view is the parent of the modal loading view? That's the part that tripped me up.
jgarbers
The table view is where this starts. User clicks on a cell, "loading" view is presented modally, load finishes, "loading" view is dismiseed, "specific" view is allocated and pushed onto the navigation stack. These last two steps could occur in the method that is called when your load actually finishes (this method could be in the table view's controller).
gerry3