views:

169

answers:

3

Hello,

I have a 4 tabbar application. The second tab has a tableviewController. When i select the second tab the tableview is displayed with it's contents and it works fine.

The problem is that that data is comming from the network and it talks 2-3 seconds to load. So when i press the second tab it goes there after the contents have been loaded.

How can i show an empty tableview (i'll put an activity indicator) and then load and show the contents?

Teo

A: 

When you start loading your data, I would add the activity indicator on top of the table view and return 0 from -numberOfSectionsInTableView: and -tableView:numberOfRowsInSection:.

Once the data is loaded, remove the activity indicator, tell the UITableView to -reloadData: and start returning the correct values for the number of sections and rows.

Thomas Müller
Note that for most applications that use overly intrusive UIActivityIndicator's, they should be using the status bar indicator: [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES].
Paul Lynch
Should this be done from -viewWillAppear? 1. Set numberOfRowsInSection to zero 2. reload data3. Start loading network data4. Set numberOfRowsInSection to xxx5. reload data
Teo
Yes, you could do this in -viewWillAppear.
Thomas Müller
Using the status bar indicator is a good idea, I agree, but especially if it might take a while I would still (also) add an activity indicator in the middle of the screen. The little indicator in the status bar could be easily missed and the user left wondering what's wrong.
Thomas Müller
A: 

I tried using viewWillAppear but the UI doesn't show up until it's finished. Also i tried -viweDidAppear with the same effect. So how can you execute something after the tableview shows up?

Teo

Tep
A: 

I found that BrowserViewController in Apple's BonjourWeb sample code does what you're seeking. I was able to pattern my tableview after this sample code successfully, so give it a try: http://developer.apple.com/iphone/library/samplecode/BonjourWeb/Introduction/Intro.html

Gorgando