views:

1126

answers:

1

Greetings!

I've added a UIActivityIndicatorView as a subview of a UITableView. The intent is to fade this view out once the underlying table has been refreshed with new data.

The problem is that the sections in the table view (e.g., A, B, C, etc.) appear to be added after the Activity Indicator appears, partially blocking the activity indicator for a moment.

Is there "a better way" (or more proper way) to be doing this sort of thing when it comes to activity indicators over table views with sections? Right now I'm doing this to fade out the loading activity indicator view:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[loading setAlpha:0.0f];
[UIView commitAnimations];

FWIW, calling the equivalent of [myTableView bringSubviewToFront:myActivityIndicatorView] doesn't appear to help matters either.

On top of that, there's the matter of removing loading from the superview. I suppose I need to use setAnimationDidStopSelector: and pass the loading view as context (and maybe I don't really need that CGContextRef line after all).

+2  A: 

It may well be easier to contain your table in a UIView as a subview, then swap in a loading view as a subview instead until your data is ready for display.

Kendall Helmstetter Gelner
Ahh, thanks! So then I'd have a parent view with two subviews - the table and the loading view, vs. making the loading view a subview of the table view.
Joe D'Andrea
Bleah. No luck. I must be doing something wrong. I've placed the table in a UIView and tied it to an IBOutlet via a new "topView" property. (Reason: I've noticed that Table View Controllers only expose "view" in IB, which is tied to the Table View, but both "view" _and_ "tableView" are ultimately set to the same table view, hence the new topView property.) I then add my loading indicator UIView as a subview of topView, but I never see it. I only see the Table View. I've even sent them to the front/back of the z-order, to no avail. (I also double-checked, and topView is not nil.) Hmm ...
Joe D'Andrea
I usually make an IBOutlet of type UITableView called "myTable" and tie that in with IB...Also, before putting in the loading view I'd remove the UITableView from the superview, then put it back when loading is done.
Kendall Helmstetter Gelner
This just in: I've stumbled upon a most handy class:http://www.bukovinski.com/2009/04/08/mbprogresshud-for-iphone/I've also contributed a few mods (in the comments of the post).
Joe D'Andrea
Just to tidy up this thread: Removing UITableView from the superview, then adding it back, works wonderfully. Another option is to have the HUD be a subview of UIWindow, but then you need to be careful when switching across views in your app. Either one works!
Joe D'Andrea