0

I want to display a "Loading" message if my table is not filled with all the information in 3 seconds. Here is what I want my table to do:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

     //First time

     UITableView *cell = [tableView cellForRowAtIndexPath:indexPath];

     //Configure table

     //Second Time
}


NSTimeInterval timeDifference = [firstTime timeIntervalSinceDate:secondTime];
if (timeDifference == 3 seconds){
   //Display Loading message
}
BigT
  • 1,413
  • 5
  • 24
  • 52
  • 3
    Did you have a question? – eric.mitchell Jul 17 '12 at 18:37
  • Well my question is how can I display a loading message if it is over 3 seconds. I cant do it the way I have here because it will run the time difference after everything is done. I cant do it before because then I wont know the time difference. I need to run it the same time as my table view. – BigT Jul 17 '12 at 19:24
  • What kind of information are you loading your table with? Pictures loaded from disk? Or downloaded text? – eric.mitchell Jul 17 '12 at 21:22

1 Answers1

0

I think you're approaching the problem wrong in your question. Instead of only showing a loading state if your data loading is taking too long, try always showing the loading state UNTIL the data load operation has completed (hopefully on a background thread which will allow your main UI thread to actually show the loading UI). There are a number of ways to achieve this, the best way for you will depend on your personal preference and existing code.

Paul Tiarks
  • 1,881
  • 1
  • 13
  • 10
  • Thats the way I have it now. My data gets loaded quickly so I wanted to have a loading message in case it takes a long time to get my data. – BigT Jul 17 '12 at 20:30
  • I'm a little confused. If it's working now, what is the problem again? – Paul Tiarks Jul 17 '12 at 20:34
  • The issue is that sometimes when I load the data into my table it goes fairly quick. Other times it takes a while to load the table. What I wanted was to have a loading message if it takes to long. – BigT Jul 17 '12 at 20:38
  • I'm assuming the variance in the time your data load takes is because it's being loaded from the network? If that's the case, then I'd say you shouldn't waste your time figuring out a way to only show the loading message if the load is taking too long. It makes for much more straightforward code and a better user experience. – Paul Tiarks Jul 17 '12 at 20:45
  • Thats right. I am getting my info from a webservice and bringing it down to view it in a table. The code I have now is making the loading message when I start to parse and when I finish parsing. The issue im having is that the loading message just flashes and it doesnt look good. I want to see if I can create the loading message if it is slow. – BigT Jul 17 '12 at 20:54
  • 1
    Perhaps create an animation block for displaying the loading message, and as a first step in the sequence, add a delay. That way, if the data loads quickly, the sequence is simply aborted during the delay (user will see nothing). – cleverbit Aug 23 '12 at 08:44