tags:

views:

20

answers:

1

I'm developing an app which has a tab bar and a UITableView, sometimes I'll need to run a function to update the database, which takes a few seconds. However, this is only needed if they want to look at a certain screen (and the data need updating) which has a UITableView on it.

I want some advice as to how, what, when and where I should show a progress indicator.

I'm thinking that I'll need something which pops up when the table view is about to be shown ?

As I say I don't know what to use to show the progress?

Also where would it be shown, would I need a new screen which is shown before the the table view or can I use and action sheet which will be dismissed automatically ?

Would like some sample code too.

A: 

There are many options for what. You can use a UIActivityIndicator (the spinning circle) or a Progress View (thermometer style) or a UILabel with the text xx% or nothing at all. If you're connecting to the Internet to get data, you should also call [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES] to show the spinning circle in the status bar.

Where is entirely up to you. Apple's own apps have put it into toolbars (c.f. EMail), in the middle of an otherwise blank view (c.f. App Store), or in a single UITableViewCell (c.f., Settings. It shows "Loading applications..." at the bottom when the app first starts while loading Settings.bundle from all installed apps.)

How largely depends on the where and what chosen, but in all cases your DB update needs to be in a background thread so you minimize the effect on the UI. If you're using a Progress View or some numerical feedback you'll want to periodically call something like:

[myViewController performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:(1.0 * currentRecord / totalRecords)] waitUntilDone:NO]
John Franklin
OK cool, unfortunately I can't have a progress where I can update at intervals, its one sql query which takes the time. So I need something which I can start and finish. Which would be a appropriate for that? I like the idea of a cell in the table, but I think I'd need to reload data afterwards. Can you provide me some examples which would work ?
Jules
The cell in the table would work. Write your UITableView's dataSource to return 1 item. When asked for a cell while loading, set the cell's `text` to "loading data...". If this is coming from a single SQL statement on the phone, consider adding some indexes to the DB to speed up the SELECT.
John Franklin
Hmmm, I've had a look at the UIActivityIndicator and it seems a bit small, I was thinking of something which occupied most of the screen, any ideas ?
Jules